Chart.js
Chart.js copied to clipboard
feat: add ESM support
Alternative of https://github.com/chartjs/Chart.js/pull/10479
More changes than expected, but still.
To import CommonJS modules in/from ESM project .cjs extension is required.
I think this PR also resolves this issue https://github.com/chartjs/Chart.js/issues/9436
If we still want to support commonjs, cjs bundle from this PR has compatible with ESM exports:
Chart.helpers = {...helpers};
Chart._adapters = _adapters;
Chart.Animation = Animation;
Chart.Animations = Animations;
Chart.animator = animator;
Chart.controllers = registry.controllers.items;
Chart.DatasetController = DatasetController;
Chart.Element = Element;
Chart.elements = elements;
Chart.Interaction = Interaction;
Chart.layouts = layouts;
Chart.platforms = platforms;
Chart.Scale = Scale;
Chart.Ticks = Ticks;
Object.assign(Chart, controllers, scales, elements, plugins, platforms);
Chart.Chart = Chart;
module.exports = Chart;
@benmccann What do you think?
I'd love to drop CJS and do ESM-only if possible
This leads to another related change needed in docs: https://www.chartjs.org/docs/master/getting-started/integration.html Should probably have ES Modules at top, update the CommonJS part and what about the Require JS?
@kurkle Done.
I will resolve conflicts later today
Should we keep the unminified UMD build? It might help people if they encounter an error in the minified build or otherwise want to debug. Perhaps we should have a chart.umd.js and chart.umd.min.js?
@benmccann maybe just emit sourcemaps for UMD bundle ?