Skip to content

Commit fb3f922

Browse files
committed
support both ESM and CommonJS
you should really switch to ESM though
1 parent 4b49550 commit fb3f922

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@ docs
5151

5252
# Compiled TypeScript
5353
lib/
54-
esm/
54+
cjs/

package.json

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@
77
"exports": {
88
".": {
99
"import": "./lib/index.js",
10-
"types": "./lib/index.d.ts"
10+
"types": "./lib/index.d.ts",
11+
"require": "./cjs/index.js"
1112
}
1213
},
14+
"main": "./cjs/index.js",
15+
"module": "./lib/index.js",
1316
"types": "./lib/index.d.ts",
1417
"sideEffects": false,
1518
"files": [
16-
"lib/**/*"
19+
"lib/**/*",
20+
"cjs/**/*"
1721
],
1822
"engines": {
1923
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
@@ -30,12 +34,17 @@
3034
"prepack": "yarn run build",
3135
"prepublish": "yarn run test",
3236
"test": "yarn run check && yarn run lint",
33-
"check": "yarn run compile --noEmit",
37+
"check": "yarn run compile:esm --noEmit",
3438
"lint": "xo ./src",
35-
"clean": "rimraf lib",
36-
"compile": "tsc",
37-
"build": "yarn run clean && yarn run compile",
38-
"dev": "yarn run clean && yarn run compile --watch"
39+
"clean:esm": "rimraf lib",
40+
"clean:cjs": "rimraf cjs",
41+
"clean": "yarn run clean:esm && yarn run clean:cjs",
42+
"compile:esm": "tsc",
43+
"compile:cjs": "tsc --outDir cjs --module commonjs",
44+
"build:esm": "yarn run clean:esm && yarn run compile:esm",
45+
"build:cjs": "yarn run clean:cjs && yarn run compile:cjs",
46+
"build": "yarn run build:esm && yarn run build:cjs",
47+
"dev": "yarn run clean:esm && yarn run compile:esm --watch"
3948
},
4049
"license": "MIT",
4150
"devDependencies": {

0 commit comments

Comments
 (0)