Skip to content

Commit 29d95af

Browse files
committed
chore(esm): hybrid library [kickoff]
1 parent 9fa7bc4 commit 29d95af

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
"scripts": {
88
"start": "tsc -w",
99
"prebuild": "rimraf dist",
10-
"build": "tsc",
11-
"postbuild": "npm-prepare-dist -s postinstall -s prepare",
10+
"build": "tsc && tsc -p tsconfig-cjs.json",
11+
"postbuild": "npm-prepare-dist -s postinstall -s prepare && yarn fix-paths",
1212
"tsc": "tsc",
1313
"demo": "ts-node demo",
1414
"lint": "eslint ./src/**/**/* --fix",
1515
"test": "jest",
16+
"fix-paths": "yarn json -I -f ./dist/package.json -e \"this.module='./esm/index.js';this.main='./cjs/index.js';this.types='./cjs/index.d.ts'\"",
1617
"postinstall": "yarn husky install",
1718
"publish:next": "yarn && yarn build && yarn test --coverage true && npm publish --folder dist --tag beta",
1819
"postversion": "git push && git push --follow-tags",
@@ -40,6 +41,7 @@
4041
"husky": "^8.0.1",
4142
"jest": "^29.1.2",
4243
"jest-fetch-mock": "^3.0.3",
44+
"json": "^11.0.0",
4345
"npm-prepare-dist": "^0.4.1",
4446
"prettier": "^2.7.1",
4547
"pretty-quick": "^3.1.3",

tsconfig-cjs.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"module": "CommonJS",
5+
"outDir": "./dist/cjs"
6+
}
7+
}

tsconfig.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
{
22
"compilerOptions": {
3-
"target": "es2017",
3+
"target": "es2015",
44
"lib": ["dom"],
55
"types": ["node", "jest"],
66
"baseUrl": "./src",
77
"esModuleInterop": true,
8-
"module": "commonjs",
8+
"module": "esnext",
9+
"moduleResolution": "Node",
910
"strictNullChecks": false,
11+
"allowSyntheticDefaultImports": true,
12+
"forceConsistentCasingInFileNames": true,
1013
"sourceMap": false,
11-
"outDir": "./dist",
14+
"outDir": "./dist/esm",
1215
"strict": true,
1316
"declaration": true,
1417
"pretty": true,
1518
"skipLibCheck": true,
16-
"resolveJsonModule": true,
1719
"alwaysStrict": true,
1820
"noImplicitAny": true,
1921
"noImplicitReturns": true

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2369,6 +2369,11 @@ json5@^2.2.1:
23692369
resolved "https://registry.yarnpkg.com/json5/-/json5-2.2.1.tgz#655d50ed1e6f95ad1a3caababd2b0efda10b395c"
23702370
integrity sha512-1hqLFMSrGHRHxav9q9gNjJ5EXznIxGVO09xQRrwplcS8qs28pZ8s8hupZAmqDwZUmVZ2Qb2jnyPOWcDH8m8dlA==
23712371

2372+
json@^11.0.0:
2373+
version "11.0.0"
2374+
resolved "https://registry.yarnpkg.com/json/-/json-11.0.0.tgz#2e84493134e2f42c131165aa22a124df38b3a3ee"
2375+
integrity sha512-N/ITv3Yw9Za8cGxuQqSqrq6RHnlaHWZkAFavcfpH/R52522c26EbihMxnY7A1chxfXJ4d+cEFIsyTgfi9GihrA==
2376+
23722377
kleur@^3.0.3:
23732378
version "3.0.3"
23742379
resolved "https://registry.yarnpkg.com/kleur/-/kleur-3.0.3.tgz#a79c9ecc86ee1ce3fa6206d1216c501f147fc07e"

0 commit comments

Comments
 (0)