-
Notifications
You must be signed in to change notification settings - Fork 11
Usage with build tools
This package is published with untranspiled JavaScript. All files are in the form of ECMAScript Modules (ESM), with .mjs
as file extension. This means that you'll need to transpile the used functions yourself, especially when used on the web.
Not every build tool or bundler will recognize .mjs
files correctly, and not every setup will transpile these files when they're in the node_modules
folder. Here's a list with commonly used tools and usage instructions:
The latest version of Webpack should transpile .mjs
files properly when used with the default Babel loader (babel-loader).
The latest version of Rollup should transpile .mjs
files properly when used with the default Babel plugin (rollup-plugin-babel).
Use the following babelify settings to transform .mjs
files in the node_modules
:
global: true,
ignore: /\/node_modules\/(?!.*.*\/.*.mjs)/,
The esmify plugin might also prove to be useful.
If you're transpiling with Babel in any other setup, use the following ignore pattern to properly ignore the node_modules
and allow .mjs
files to be transpiled:
ignore: [/\/node_modules\/(?!.*.*\/.*.mjs)/],
This can be added in your babel.config.js
, .babelrc
or package.json
; quotes will be necessary for JSON-based configurations.
Run Node with support for ECMAScript Modules enabled:
node --experimental-modules my-app.mjs