From 40e9029a59d0b7851d9cb6044bcc73d1411a381e Mon Sep 17 00:00:00 2001 From: Jukka Kurkela Date: Wed, 24 Jun 2020 02:02:51 +0300 Subject: [PATCH] ESM build, with helpers separated (#7400) * ESM build, with helpers separated * Remove umd environment * Include the chunks in package --- .gitignore | 1 + karma.conf.js | 2 +- package.json | 6 +++--- rollup.config.js | 37 ++++++++++++++----------------------- src/index.esm.js | 6 ++++++ 5 files changed, 25 insertions(+), 27 deletions(-) create mode 100644 src/index.esm.js diff --git a/.gitignore b/.gitignore index 3adb827bd..e941ca2d8 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ /custom /dist /gh-pages +/helpers # Node.js node_modules/ diff --git a/karma.conf.js b/karma.conf.js index 9ca016bd9..8ae923eb4 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -21,7 +21,7 @@ module.exports = function(karma) { // better with source mapping. In other cases, pick the minified build to // make sure that the minification process (terser) doesn't break anything. 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({ frameworks: ['jasmine'], diff --git a/package.json b/package.json index 288116294..546328c08 100644 --- a/package.json +++ b/package.json @@ -24,9 +24,8 @@ "url": "https://github.com/chartjs/Chart.js/issues" }, "files": [ - "composer.json", - "dist/*.css", - "dist/*.js" + "dist/*.js", + "helpers/**/*.js" ], "scripts": { "autobuild": "rollup -c -w", @@ -57,6 +56,7 @@ "eslint-config-chartjs": "^0.2.0", "eslint-config-esnext": "^4.1.0", "eslint-plugin-html": "^6.0.2", + "glob": "^7.1.6", "jasmine": "^3.5.0", "jasmine-core": "^3.5.0", "karma": "^5.0.9", diff --git a/rollup.config.js b/rollup.config.js index 51a4bc5e5..785a335b8 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -3,6 +3,7 @@ const babel = require('rollup-plugin-babel'); const cleanup = require('rollup-plugin-cleanup'); +const glob = require('glob'); const inject = require('@rollup/plugin-inject'); const json = require('@rollup/plugin-json'); 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 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 = `/*! * Chart.js v${pkg.version} @@ -67,10 +76,10 @@ module.exports = [ }, // ES6 builds - // dist/chart.esm.min.js // dist/chart.esm.js + // helpers/*.js { - input, + input: inputESM, plugins: [ json(), resolve(), @@ -79,29 +88,11 @@ module.exports = [ }) ], output: { - name: 'Chart', - file: 'dist/chart.esm.js', + dir: './', + chunkFileNames: 'helpers/chunks/[name].js', banner, format: 'esm', indent: false, }, - }, - { - input, - plugins: [ - json(), - resolve(), - terser({ - output: { - preamble: banner - } - }) - ], - output: { - name: 'Chart', - file: 'dist/chart.esm.min.js', - format: 'esm', - indent: false, - }, - }, + } ]; diff --git a/src/index.esm.js b/src/index.esm.js new file mode 100644 index 000000000..3222ea4f4 --- /dev/null +++ b/src/index.esm.js @@ -0,0 +1,6 @@ +export * from './controllers'; +export * from './core'; +export * from './elements'; +export * from './platform'; +export * from './plugins'; +export * from './scales'; -- 2.47.2