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?