Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESM build, with helpers separated #7400

Merged
merged 5 commits into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/custom
/dist
/gh-pages
/helpers

# Node.js
node_modules/
Expand Down
2 changes: 1 addition & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,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'],
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
37 changes: 14 additions & 23 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,22 @@

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;
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}
Expand Down Expand Up @@ -67,10 +76,10 @@ module.exports = [
},

// ES6 builds
// dist/chart.esm.min.js
// dist/chart.esm.js
kurkle marked this conversation as resolved.
Show resolved Hide resolved
// helpers/*.js
{
input,
input: inputESM,
plugins: [
json(),
resolve(),
Expand All @@ -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,
},
},
}
];
6 changes: 6 additions & 0 deletions src/index.esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export * from './controllers';
export * from './core';
export * from './elements';
export * from './platform';
export * from './plugins';
export * from './scales';