Skip to content

Commit 9cb2bc6

Browse files
Revert "build: remove commonjs build (#272)" (#273)
This reverts commit 24b6e5e. BREAKING CHANGE: Added the CommonJS build again because Jest does not support ESM yet.
1 parent 24b6e5e commit 9cb2bc6

2 files changed

Lines changed: 31 additions & 6 deletions

File tree

esbuild.config.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,38 @@ import esbuild from 'esbuild';
33

44
execSync('tsc -p tsconfig.build.json', { stdio: 'inherit' });
55

6-
await esbuild.build({
6+
const commonConfig = {
77
entryPoints: ['src/index.tsx'],
88
bundle: true,
99
sourcemap: true,
1010
minify: true,
1111
target: ['es2020'],
12-
format: 'esm',
13-
outfile: 'dist/index.js',
14-
packages: 'external' as const,
15-
splitting: false,
12+
13+
// Keep imports like "Chakra.Menu"
1614
treeShaking: true,
15+
16+
// Don't let esbuild split files — Chakra compound components break
17+
splitting: false,
18+
19+
// Important for Chakra v3 (which uses modern ESM + emotion)
1720
supported: {
1821
'import-meta': true,
1922
},
23+
};
24+
25+
// ESM build - externalize all packages for tree-shaking in bundlers
26+
await esbuild.build({
27+
...commonConfig,
28+
outfile: 'dist/index.js',
29+
format: 'esm',
30+
packages: 'external' as const,
31+
});
32+
33+
// CJS build - bundle dependencies to avoid ESM/CJS interop issues
34+
// Only externalize React (peer dependency)
35+
await esbuild.build({
36+
...commonConfig,
37+
outfile: 'dist/index.cjs',
38+
format: 'cjs',
39+
external: ['react', 'react-dom', 'react/jsx-runtime'],
2040
});

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"exports": {
88
".": {
99
"types": "./dist/index.d.ts",
10-
"import": "./dist/index.js"
10+
"import": "./dist/index.js",
11+
"require": "./dist/index.cjs"
1112
}
1213
},
1314
"types": "dist/index.d.ts",
@@ -46,6 +47,10 @@
4647
{
4748
"path": "dist/index.js",
4849
"limit": "300 kB"
50+
},
51+
{
52+
"path": "dist/index.cjs",
53+
"limit": "400 kB"
4954
}
5055
],
5156
"devDependencies": {

0 commit comments

Comments
 (0)