Skip to content

Commit

Permalink
Add exports to package.json to satisfy nodejs --experimental-module u…
Browse files Browse the repository at this point in the history
…sers

Fixes #206
This ensures that consumers using --experimental-modules with node 12+
will import the esm version of this package.

This package's export MUST have .mjs file extension... (because
otherwise the entire package must be specified as type: module)
This package's export MUST use exports field in the package.json
	see https://nodejs.org/api/packages.html#conditional-exports

Not sure how to test this with a bunch of different project styles..
webpack and other loaders _should_ be fine with importing from the
`module` field with a `.mjs` file extension?
  • Loading branch information
jamie-pate committed Feb 12, 2022
1 parent cc4f9ae commit 04aa7d9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion package.json
Expand Up @@ -20,6 +20,10 @@
],
"main": "dist.es5/index.js",
"module": "dist.es5m/index.js",
"exports": {
"import": "./dist.es5m/index.mjs",
"require": "./dist.es5/index.js"
},
"es2015": "dist.es2015/index.js",
"typings": "dist.es2015/index",
"sideEffects": false,
Expand All @@ -28,7 +32,7 @@
"build": "yarn build-modern && yarn build-es5 && yarn build-es5m",
"build-modern": "tsc -p src",
"build-es5": "tsc -p src --target es5 --outDir dist.es5",
"build-es5m": "yarn build-es5 -m es2015 --outDir dist.es5m",
"build-es5m": "yarn build-es5 -m es2015 --outDir dist.es5m; mv index.js index.mjs; mv index.spec.js index.spec.mjs",
"build-watch": "yarn build-es5 -w",
"clean": "rimraf 'dist*'",
"lint": "eslint 'src/*.ts'",
Expand Down

0 comments on commit 04aa7d9

Please sign in to comment.