Skip to content

Commit 7fbfdec

Browse files
Adding commonjs configurations
1 parent 6966bc9 commit 7fbfdec

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

package.json

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,31 @@
1717
},
1818
"exports": {
1919
"./vanilla": {
20-
"import": "./dist/vanilla/index.js",
21-
"types": "./dist/vanilla/index.d.ts"
20+
"import": {
21+
"types": "./dist/esm/vanilla/index.d.js",
22+
"default": "./dist/esm/vanilla/index.js"
23+
},
24+
"require": {
25+
"types": "./dist/cjs/vanilla/index.d.js",
26+
"default": "./dist/cjs/vanilla/index.js"
27+
}
2228
},
2329
"./react": {
24-
"import": "./dist/react/index.js",
25-
"types": "./dist/react/index.d.ts"
30+
"import": {
31+
"types": "./dist/esm/react/index.d.js",
32+
"default": "./dist/esm/react/index.js"
33+
},
34+
"require": {
35+
"types": "./dist/cjs/react/index.d.js",
36+
"default": "./dist/cjs/react/index.js"
37+
}
2638
}
2739
},
2840
"scripts": {
2941
"dev": "vite",
30-
"build": "tsc",
42+
"build:esm": "tsc -p tsconfig.json && echo '{\"type\": \"module\"}' > dist/esm/react/package.json && echo '{\"type\": \"module\"}' > dist/esm/vanilla/package.json",
43+
"build:cjs": "tsc -p tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > dist/cjs/react/package.json && echo '{\"type\": \"commonjs\"}' > dist/cjs/vanilla/package.json",
44+
"build": "npm run build:esm && npm run build:cjs",
3145
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
3246
"ci": "npm run lint && npm run build && npm run build:storybook",
3347
"storybook": "storybook dev -p 6006",

tsconfig.cjs.json

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

tsconfig.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
"skipLibCheck": true,
88

99
/* Bundler mode */
10-
"moduleResolution": "NodeNext",
1110
"resolveJsonModule": true,
1211
"isolatedModules": true,
1312
"moduleDetection": "force",
14-
"outDir": "dist",
13+
"outDir": "dist/esm",
1514
"sourceMap": true,
1615
"declaration": true,
1716
"jsx": "react-jsx",
@@ -23,5 +22,5 @@
2322
"noUnusedParameters": false,
2423
"noFallthroughCasesInSwitch": true
2524
},
26-
"include": ["src"]
25+
"include": ["./src"]
2726
}

0 commit comments

Comments
 (0)