npm-es-modules-6-webpack
v0.0.2
Published
Breakdown of 7 different ways to use ES modules with NPM today.
Downloads
3
Maintainers
Readme
npm-es-modules-6-webpack
Breakdown of 7 different ways to use ES modules with npm today.
WARNING: this approach is currently a broken WIP, and its exports do not behave correctly. All other approaches work as intended.
This approach uses babel+webpack to compile all Node.js and browser source files.
- Source files end in
.mjs
- Supports all three targets
main
,module
, andbrowser
- Unfortunately, Webpack does not support outputting ES module targets (issue).
- The
main
andbrowser
targets are compiled, but themodule
target is unable to be compiled. - Supports
node >= 8
, whereas the rollup version is capable of supportingnode >= 4
by compiling themodule
target as well. - Unless you have a good project-specific reason to use webpack over rollup, I would strongly recommend using rollup to bundle ES6 module libraries (at least until this webpack issue is addressed).
Approaches
- naive - The most naive possible use of ES modules supporting our functionality. This approach is broken and provided as an example starting point.
- babel - Uses babel to transpile all Node.js and browser source files.
- esm-rollup - Uses esm for Node.js and babel+rollup to compile browser source files.
- esm-webpack - Uses esm for Node.js and babel+webpack to compile browser source files.
- rollup - Uses babel+rollup to compile all Node.js and browser source files.
- webpack - Uses babel+webpack to compile all Node.js and browser source files.
- typescript - Uses typescript to transpile all Node.js and browser source files.
License
MIT © Travis Fischer