Skip to content

Commit 3ed1a26

Browse files
committed
Use "module" instead of "main" when exposing ESM.
In order for this package to work out of the box with webpack, we need to either name the index.js "index.mjs" (and not have a file extension, e.g. "esm/index") or use the "module" field in package.json. Otherwise it's not easily possible to load this through webpack without transpiling it.
1 parent f0287d9 commit 3ed1a26

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,4 @@ typings/
8282

8383
# End of https://www.gitignore.io/api/node
8484

85-
esm/
85+
dist/

package.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
"name": "rxjs-hooks",
33
"version": "0.3.2",
44
"description": "React hooks for RxJS",
5-
"main": "esm/index.js",
5+
"module": "dist/esm/index.js",
6+
"main": "dist/cjs/index.js",
67
"author": "LongYinan <[email protected]>",
78
"license": "MIT",
8-
"typings": "esm/index.d.ts",
9+
"typings": "dist/cjs/index.d.ts",
910
"sideEffects": false,
1011
"scripts": {
11-
"build": "rm -rf esm && tsc -p src/tsconfig.json --outDir esm",
12+
"build": "yarn build:esm && yarn build:cjs",
13+
"build:esm": "rm -rf dist/esm && tsc -p src/tsconfig.json --module es2015 --target es5 --outDir dist/esm",
14+
"build:cjs": "rm -rf dist/cjs && tsc -p src/tsconfig.json --module commonjs --target es5 --outDir dist/cjs",
1215
"lint": "tslint -c tslint.json -p src/tsconfig.json",
1316
"start": "webpack-dev-server --config ./tools/webpack.config.js --progress --color",
1417
"test": "NODE_ENV=test jest --no-cache --ci"

0 commit comments

Comments
 (0)