ESM build, with helpers separated (#7400)

* ESM build, with helpers separated
* Remove umd environment
* Include the chunks in package
This commit is contained in:
Jukka Kurkela 2020-06-24 02:02:51 +03:00 committed by GitHub
parent 8ac700961a
commit 40e9029a59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 27 deletions

1
.gitignore vendored
View File

@ -3,6 +3,7 @@
/custom /custom
/dist /dist
/gh-pages /gh-pages
/helpers
# Node.js # Node.js
node_modules/ node_modules/

View File

@ -21,7 +21,7 @@ module.exports = function(karma) {
// better with source mapping. In other cases, pick the minified build to // better with source mapping. In other cases, pick the minified build to
// make sure that the minification process (terser) doesn't break anything. // make sure that the minification process (terser) doesn't break anything.
const regex = karma.autoWatch ? /chart\.js$/ : /chart\.min\.js$/; const regex = karma.autoWatch ? /chart\.js$/ : /chart\.min\.js$/;
const build = builds.filter(v => v.output.file.match(regex))[0]; const build = builds.filter(v => v.output.file && v.output.file.match(regex))[0];
karma.set({ karma.set({
frameworks: ['jasmine'], frameworks: ['jasmine'],

View File

@ -24,9 +24,8 @@
"url": "https://github.com/chartjs/Chart.js/issues" "url": "https://github.com/chartjs/Chart.js/issues"
}, },
"files": [ "files": [
"composer.json", "dist/*.js",
"dist/*.css", "helpers/**/*.js"
"dist/*.js"
], ],
"scripts": { "scripts": {
"autobuild": "rollup -c -w", "autobuild": "rollup -c -w",
@ -57,6 +56,7 @@
"eslint-config-chartjs": "^0.2.0", "eslint-config-chartjs": "^0.2.0",
"eslint-config-esnext": "^4.1.0", "eslint-config-esnext": "^4.1.0",
"eslint-plugin-html": "^6.0.2", "eslint-plugin-html": "^6.0.2",
"glob": "^7.1.6",
"jasmine": "^3.5.0", "jasmine": "^3.5.0",
"jasmine-core": "^3.5.0", "jasmine-core": "^3.5.0",
"karma": "^5.0.9", "karma": "^5.0.9",

View File

@ -3,6 +3,7 @@
const babel = require('rollup-plugin-babel'); const babel = require('rollup-plugin-babel');
const cleanup = require('rollup-plugin-cleanup'); const cleanup = require('rollup-plugin-cleanup');
const glob = require('glob');
const inject = require('@rollup/plugin-inject'); const inject = require('@rollup/plugin-inject');
const json = require('@rollup/plugin-json'); const json = require('@rollup/plugin-json');
const resolve = require('@rollup/plugin-node-resolve').default; const resolve = require('@rollup/plugin-node-resolve').default;
@ -10,6 +11,14 @@ const terser = require('rollup-plugin-terser').terser;
const pkg = require('./package.json'); const pkg = require('./package.json');
const input = 'src/index.js'; const input = 'src/index.js';
const inputESM = {
'dist/chart.esm': 'src/index.esm.js',
};
glob('src/helpers/helpers.*.js', (_er, files) => {
files.forEach(file => {
inputESM[file.replace(/src\/|helpers\.|\.js/g, '')] = file;
});
});
const banner = `/*! const banner = `/*!
* Chart.js v${pkg.version} * Chart.js v${pkg.version}
@ -67,10 +76,10 @@ module.exports = [
}, },
// ES6 builds // ES6 builds
// dist/chart.esm.min.js
// dist/chart.esm.js // dist/chart.esm.js
// helpers/*.js
{ {
input, input: inputESM,
plugins: [ plugins: [
json(), json(),
resolve(), resolve(),
@ -79,29 +88,11 @@ module.exports = [
}) })
], ],
output: { output: {
name: 'Chart', dir: './',
file: 'dist/chart.esm.js', chunkFileNames: 'helpers/chunks/[name].js',
banner, banner,
format: 'esm', format: 'esm',
indent: false, indent: false,
}, },
},
{
input,
plugins: [
json(),
resolve(),
terser({
output: {
preamble: banner
} }
})
],
output: {
name: 'Chart',
file: 'dist/chart.esm.min.js',
format: 'esm',
indent: false,
},
},
]; ];

6
src/index.esm.js Normal file
View File

@ -0,0 +1,6 @@
export * from './controllers';
export * from './core';
export * from './elements';
export * from './platform';
export * from './plugins';
export * from './scales';