From 04aa7d995d0ced5cdc69be3885fff005016e0dab Mon Sep 17 00:00:00 2001 From: Jamie Pate Date: Fri, 11 Feb 2022 17:11:45 -0800 Subject: [PATCH] Add exports to package.json to satisfy nodejs --experimental-module users 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? --- package.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 9c4cec0..c46a370 100644 --- a/package.json +++ b/package.json @@ -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, @@ -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'",