Skip to content

Commit 507889a

Browse files
build esm and cjs both (#148)
1 parent fc62dd7 commit 507889a

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ jobs:
3636
run: yarn fmt:check
3737

3838
- name: Typescript build
39-
run: yarn typescript
39+
run: yarn build

package.json

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,21 @@
77
"dist/"
88
],
99
"exports": {
10-
".": "./dist/index.js",
11-
"./react-router": "./dist/react-router/index.js",
12-
"./next": "./dist/next/index.js"
10+
".": {
11+
"import": "./dist/esm/index.js",
12+
"require": "./dist/cjs/index.js",
13+
"default": "./dist/esm/index.js"
14+
},
15+
"./react-router": {
16+
"import": "./dist/esm/react-router/index.js",
17+
"require": "./dist/cjs/react-router/index.js",
18+
"default": "./dist/esm/react-router/index.js"
19+
},
20+
"./next": {
21+
"import": "./dist/esm/next/index.js",
22+
"require": "./dist/cjs/next/index.js",
23+
"default": "./dist/esm/next/index.js"
24+
}
1325
},
1426
"scripts": {
1527
"test": "jest",
@@ -18,10 +30,12 @@
1830
"lint:cache": "eslint src --ext .js,.jsx,.ts,.tsx --cache",
1931
"fmt": "LOG_LEVEL= prettier-eslint --write --no-semi $PWD/'src/**/*.ts' $PWD/'src/**/*.tsx'",
2032
"fmt:check": "LOG_LEVEL= prettier-eslint --list-different --no-semi $PWD/'src/**/*.ts' $PWD/'src/**/*.tsx'",
21-
"typescript": "rm -rf dist && rm -f .tsbuildinfo && tsc",
2233
"typecheck": "tsc --noEmit",
23-
"prepack": "npm run typescript",
24-
"repl": "ts-node"
34+
"prepack": "npm run build",
35+
"repl": "ts-node",
36+
"build:esm": "tsc",
37+
"build:cjs": "tsc --module commonjs --outDir dist/cjs",
38+
"build": "rm -rf dist && rm -f .tsbuildinfo && npm run build:esm && npm run build:cjs"
2539
},
2640
"repository": {
2741
"type": "git",
@@ -90,4 +104,4 @@
90104
}
91105
},
92106
"packageManager": "[email protected]"
93-
}
107+
}

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"compilerOptions": {
33
"incremental": true,
44
"target": "es5",
5-
"module": "commonjs",
5+
"module": "ES2015",
66
"lib": [
77
"es2020",
88
"dom"
@@ -11,7 +11,7 @@
1111
"checkJs": true,
1212
"jsx": "react",
1313
"declaration": true,
14-
"outDir": "./dist/",
14+
"outDir": "./dist/esm/",
1515
"tsBuildInfoFile": ".tsbuildinfo",
1616
"strict": true,
1717
"noUnusedLocals": true,

0 commit comments

Comments
 (0)