npm-es-modules-7-typescript
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

npm-es-modules-7-typescript

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

NPM Build Status JavaScript Style Guide

This approach uses typescript to transpile all Node.js and browser source files.

  • Source files end in .ts
  • Supports all three targets main module, and browser
  • Two compilation passes are necessary, one for targeting commonjs and one targeting esm
  • Currently, commonjs users have to add default to require statements: require('npm-es-modules-7-typescript').default
    • If you know how to prevent this, please let me know!
  • Resulting module supports node >= 4 (or whatever we specify in our tsconfig.json) instead of node >= 8
  • Overall, this feels like the cleanest and most future-proof approach.

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-7-typescript

Weekly Downloads

1

Version

0.0.2

License

MIT

Unpacked Size

20.3 kB

Total Files

30

Last publish

Collaborators

  • fisch0920