npm-es-modules-1-naive

0.0.2 • Public • Published

npm-es-modules-1-naive

Breakdown of 7 different ways to use ES modules with npm today.

NPM Build Status JavaScript Style Guide

In this approach, we use normal .js file extensions for es modules and no transpilation.

It is relatively simple and straightforward but breaks several of our module goals:

  • Not usable from node.js because its main field is an es module whereas it should be a commonjs file.
  • Not usable from the browser via webpack or rollup because its browser field is an es module whereas it should be a commonjs file.
  • The only advantage of this approach is its simplicity, and this may be good enough if you are just working on private modules.
  • Warning: unless you are using strictly local or private modules, we strongly encourage you not to use this approach in practice. It is meant as an example of what not to do when transitioning from commonjs to ES modules, and if you publish a module publicly using this approach, the JavaScript Gods will find and shame you.
  • Unfortunately AFAIK, there is really nothing built into the npm ecosystem which prevents you from publishing broken modules like this, although as ES modules gain popularity over the coming years, I believe this will be addressed.

Approaches

  1. naive - The most naive possible use of ES modules supporting our functionality. This approach is broken and provided as an example starting point.
  2. babel - Uses babel to transpile all Node.js and browser source files.
  3. esm-rollup - Uses esm for Node.js and babel+rollup to compile browser source files.
  4. esm-webpack - Uses esm for Node.js and babel+webpack to compile browser source files.
  5. rollup - Uses babel+rollup to compile all Node.js and browser source files.
  6. webpack - Uses babel+webpack to compile all Node.js and browser source files.
  7. typescript - Uses typescript to transpile all Node.js and browser source files.

License

MIT © Travis Fischer

Package Sidebar

Install

npm i npm-es-modules-1-naive

Weekly Downloads

1

Version

0.0.2

License

MIT

Unpacked Size

5.74 kB

Total Files

9

Last publish

Collaborators

  • fisch0920