Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

147
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda