mirror of
https://github.com/chartjs/Chart.js
synced 2025-04-29 15:57:22 +08:00
feat: restore commonjs bundle (#10984)
This commit is contained in:
parent
185bb97d2e
commit
35fd6204b9
6
auto/auto.cjs
Normal file
6
auto/auto.cjs
Normal file
@ -0,0 +1,6 @@
|
||||
const exports = require('../dist/chart.cjs');
|
||||
const {Chart, registerables} = exports;
|
||||
|
||||
Chart.register(...registerables);
|
||||
|
||||
module.exports = Object.assign(Chart, exports);
|
1
helpers/helpers.cjs
Normal file
1
helpers/helpers.cjs
Normal file
@ -0,0 +1 @@
|
||||
module.exports = require('../dist/helpers.cjs');
|
@ -15,15 +15,18 @@
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/types.d.ts",
|
||||
"import": "./dist/chart.js"
|
||||
"import": "./dist/chart.js",
|
||||
"require": "./dist/chart.cjs"
|
||||
},
|
||||
"./auto": {
|
||||
"types": "./auto/auto.d.ts",
|
||||
"import": "./auto/auto.js"
|
||||
"import": "./auto/auto.js",
|
||||
"require": "./auto/auto.cjs"
|
||||
},
|
||||
"./helpers": {
|
||||
"types": "./helpers/helpers.d.ts",
|
||||
"import": "./helpers/helpers.js"
|
||||
"import": "./helpers/helpers.js",
|
||||
"require": "./helpers/helpers.cjs"
|
||||
}
|
||||
},
|
||||
"types": "./dist/types.d.ts",
|
||||
|
6
pnpm-lock.yaml
generated
6
pnpm-lock.yaml
generated
@ -152,6 +152,12 @@ importers:
|
||||
dependencies:
|
||||
chart.js: link:../../..
|
||||
|
||||
test/integration/node-commonjs:
|
||||
specifiers:
|
||||
chart.js: workspace:*
|
||||
dependencies:
|
||||
chart.js: link:../../..
|
||||
|
||||
test/integration/react-browser:
|
||||
specifiers:
|
||||
'@babel/core': ^7.0.0
|
||||
|
@ -77,5 +77,26 @@ export default [
|
||||
indent: false,
|
||||
sourcemap: true,
|
||||
},
|
||||
},
|
||||
|
||||
// CommonJS builds
|
||||
// dist/chart.js
|
||||
// helpers/*.js
|
||||
{
|
||||
input: {
|
||||
'dist/chart': 'src/index.ts',
|
||||
'dist/helpers': 'src/helpers/index.ts'
|
||||
},
|
||||
plugins: plugins(),
|
||||
external: _ => (/node_modules/).test(_),
|
||||
output: {
|
||||
dir: './',
|
||||
chunkFileNames: 'dist/chunks/[name].cjs',
|
||||
entryFileNames: '[name].cjs',
|
||||
banner,
|
||||
format: 'commonjs',
|
||||
indent: false,
|
||||
sourcemap: true,
|
||||
},
|
||||
}
|
||||
];
|
||||
|
10
test/integration/node-commonjs/package.json
Normal file
10
test/integration/node-commonjs/package.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"private": true,
|
||||
"description": "chart.js should work in Node",
|
||||
"scripts": {
|
||||
"test": "node test.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"chart.js": "workspace:*"
|
||||
}
|
||||
}
|
7
test/integration/node-commonjs/test.js
Normal file
7
test/integration/node-commonjs/test.js
Normal file
@ -0,0 +1,7 @@
|
||||
const {Chart} = require('chart.js');
|
||||
const {valueOrDefault} = require('chart.js/helpers');
|
||||
|
||||
Chart.register({
|
||||
id: 'TEST_PLUGIN',
|
||||
dummyValue: valueOrDefault(0, 1)
|
||||
});
|
@ -1,10 +1,7 @@
|
||||
/* eslint-disable es/no-dynamic-import */
|
||||
Promise.all([
|
||||
import('chart.js'),
|
||||
import('chart.js/helpers')
|
||||
]).then(([{Chart}, {valueOrDefault}]) => {
|
||||
Chart.register({
|
||||
id: 'TEST_PLUGIN',
|
||||
dummyValue: valueOrDefault(0, 1)
|
||||
});
|
||||
const {Chart} = require('chart.js');
|
||||
const {valueOrDefault} = require('chart.js/helpers');
|
||||
|
||||
Chart.register({
|
||||
id: 'TEST_PLUGIN',
|
||||
dummyValue: valueOrDefault(0, 1)
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user