Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

144
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!