Skip to content

Commit 9d94c21

Browse files
committed
build!: drop the CommonJS build
The package ships only its ES module build, with an exports map and no main or module fields, as tree-shakeable packages of the Trigen baseline do. The default condition lets Node.js 20.19+ and 22.12+ require() it. The build clears dist first, so an old index.cjs cannot be published. BREAKING CHANGE: react-chartjs-2 is ESM only. Bundlers and Node.js 20.19+ or 22.12+ load it as before; older Node.js needs ESM code, and Jest needs to transform the package or run with ES modules support. See https://react-chartjs-2.js.org/docs/migration-to-v6/
1 parent f104440 commit 9d94c21

2 files changed

Lines changed: 14 additions & 12 deletions

File tree

‎package.json‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,17 @@
2424
],
2525
"sideEffects": false,
2626
"types": "./dist/index.d.ts",
27-
"exports": "./src/index.ts",
27+
"exports": {
28+
".": "./src/index.ts",
29+
"./package.json": "./package.json"
30+
},
2831
"publishConfig": {
29-
"main": "./dist/index.cjs",
30-
"module": "./dist/index.js",
3132
"exports": {
32-
"types": "./dist/index.d.ts",
33-
"import": "./dist/index.js",
34-
"require": "./dist/index.cjs"
33+
".": {
34+
"types": "./dist/index.d.ts",
35+
"default": "./dist/index.js"
36+
},
37+
"./package.json": "./package.json"
3538
},
3639
"directory": "package",
3740
"linkDirectory": false
@@ -45,7 +48,9 @@
4548
"prepublishOnly": "run test build clear:package clean-publish",
4649
"postpublish": "pnpm clear:package",
4750
"emitDeclarations": "tsc --emitDeclarationOnly -p tsconfig.build.json",
48-
"build": "run -p [ vite build ] emitDeclarations",
51+
"clear:dist": "del ./dist",
52+
"build:dist": "run -p [ vite build ] emitDeclarations",
53+
"build": "run clear:dist build:dist",
4954
"storybook": "storybook dev -p 6006 --no-open",
5055
"storybook:build": "storybook build",
5156
"sandboxes:build": "pnpm -r --filter \"./sandboxes/**\" build",

‎vite.config.js‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,15 @@ export default defineConfig({
77
build: {
88
target: 'esnext',
99
lib: {
10-
// CommonJS stays: it was dropped once and restored in v5.1
11-
formats: ['es', 'cjs'],
10+
formats: ['es'],
1211
entry: {
1312
index: './src/index.ts'
1413
}
1514
},
1615
rolldownOptions: {
1716
external: id => /^(react|chart\.js)(\/|$)/.test(id),
1817
output: {
19-
topLevelVar: false,
20-
// rolldown adds the directive only when the sources have it, and CommonJS of the package always ran strict
21-
strict: true
18+
topLevelVar: false
2219
}
2320
},
2421
sourcemap: true,

0 commit comments

Comments
 (0)