Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

152
Visualizações
How to configure webpack to build a frontend package available in npmjs.com

I use Webpack to bundle a JavaScript library into a stand-alone module that can be used by modern browsers in this way:

<script type="module">
  import { configureCart } from "/assets/liquid-ajax-cart.js";
  configureCart('addToCartCssClass', 'js-ajax-cart-open');
</script>

In the Webpack config I use library.type = "module" to achieve this:

output: {
  filename,
  path: path.resolve(__dirname, folder),
  library: {
    type: 'module',
  },
},
experiments: {
  outputModule: true
}

Now I want to publish the library on npmjs.com but I confused which library type I should use for it and should I change anything else in my Webpack config for npm package in general.

The purpose is to have possibility to download the package from npmjs:

npm install liquid-ajax-cart

and then use it with webpack or any other JS bundlers:

import { configureCart } from 'liquid-ajax-cart';
configureCart('addToCartCssClass', 'js-ajax-cart-open');

Since the package will not be used by nodejs directly I suppose I don't need to transform the code into 'commonjs' or 'amd' module typ? If so, will all the bundlers "understand" and work correctly with es6 module from npm package?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda