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

Allow ESM files to be used in Node.js #10479

Merged
merged 5 commits into from
Jul 30, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 0 additions & 5 deletions auto/auto.esm.js

This file was deleted.

5 changes: 5 additions & 0 deletions auto/auto.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {Chart, registerables} from '../dist/chart.mjs';

Chart.register(...registerables);

export default Chart;
File renamed without changes.
4 changes: 2 additions & 2 deletions auto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"private": true,
"description": "auto registering package",
"main": "auto.js",
"module": "auto.esm.js",
"types": "auto.esm.d.ts"
"module": "auto.mjs",
"types": "auto.mts"
}
2 changes: 1 addition & 1 deletion docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ module.exports = {
config.merge({
resolve: {
alias: {
'chart.js': path.resolve(__dirname, '../../dist/chart.esm.js'),
'chart.js': path.resolve(__dirname, '../../dist/chart.mjs'),
}
}
})
Expand Down
2 changes: 1 addition & 1 deletion docs/scripts/components.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Add Chart components needed in samples here.
// Usable through `components[name]`.
export {Tooltip} from '../../dist/chart.esm';
export {Tooltip} from '../../dist/chart.mjs';
3 changes: 1 addition & 2 deletions docs/scripts/helpers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Add helpers needed in samples here.
// Usable through `helpers[name]`.
export {color, getHoverColor, easingEffects} from '../../dist/helpers.esm';

export {color, getHoverColor, easingEffects} from '../../dist/helpers.mjs';
2 changes: 1 addition & 1 deletion docs/scripts/register.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Chart, registerables} from '../../dist/chart.esm';
import {Chart, registerables} from '../../dist/chart.mjs';
import Log2Axis from './log2';
import './derived-bubble';
import analyzer from './analyzer';
Expand Down
2 changes: 1 addition & 1 deletion docs/scripts/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import colorLib from '@kurkle/color';
import {DateTime} from 'luxon';
import 'chartjs-adapter-luxon';
import {valueOrDefault} from '../../dist/helpers.esm';
import {valueOrDefault} from '../../dist/helpers.mjs';

// Adapted from http://indiegamr.com/generate-repeatable-random-numbers-in-js/
var _seed = Date.now();
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"private": true,
"description": "helper package",
"main": "helpers.js",
"module": "helpers.esm.js",
"types": "helpers.esm.d.ts"
"module": "helpers.mjs",
"types": "helpers.mts"
}
16 changes: 5 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"jsdelivr": "dist/chart.min.js",
"unpkg": "dist/chart.min.js",
"main": "dist/chart.js",
"module": "dist/chart.esm.js",
"module": "dist/chart.mjs",
"types": "types/index.esm.d.ts",
"keywords": [
"canvas",
Expand All @@ -25,16 +25,10 @@
"url": "https://github.com/chartjs/Chart.js/issues"
},
"files": [
"auto/package.json",
"auto/**/*.js",
"auto/**/*.d.ts",
"dist/*.js",
"dist/chunks/*.js",
"types/*.d.ts",
"types/helpers/*.d.ts",
"helpers/package.json",
"helpers/**/*.js",
"helpers/**/*.d.ts"
"auto/**",
"dist/**",
"types/**",
"helpers/**"
],
"scripts": {
"autobuild": "rollup -c -w",
Expand Down
34 changes: 29 additions & 5 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ 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',
'dist/helpers.esm': 'src/helpers/index.js'
};

const banner = `/*!
* Chart.js v${pkg.version}
Expand Down Expand Up @@ -60,10 +56,38 @@ module.exports = [
},

// ES6 builds
// dist/chart.mjs
// helpers/*.js
{
input: {
'dist/chart': 'src/index.esm.js',
'dist/helpers': 'src/helpers/index.js'
},
plugins: [
json(),
resolve(),
cleanup({
sourcemap: true
}),
],
output: {
dir: './',
chunkFileNames: 'dist/chunks/[name].mjs',
entryFileNames: '[name].mjs',
banner,
format: 'esm',
indent: false,
},
},

// Legacy ES6 builds for backwards compatibility. Remove for Chart.js 4.0
// dist/chart.esm.js
// helpers/*.js
{
input: inputESM,
input: {
'dist/chart.esm': 'src/index.esm.js',
'dist/helpers.esm': 'src/helpers/index.js'
},
plugins: [
json(),
resolve(),
Expand Down