Skip to content

Commit

Permalink
Allow ESM files to be used in Node.js
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Jul 14, 2022
1 parent 59a2d53 commit 76c9e7f
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/.vuepress/config.js
Expand Up @@ -86,7 +86,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/utils.js
@@ -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
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"
}
2 changes: 1 addition & 1 deletion package.json
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 Down
9 changes: 5 additions & 4 deletions rollup.config.js
Expand Up @@ -7,8 +7,8 @@ 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'
'dist/chart': 'src/index.esm.js',
'dist/helpers': 'src/helpers/index.js'
};

const banner = `/*!
Expand Down Expand Up @@ -60,7 +60,7 @@ module.exports = [
},

// ES6 builds
// dist/chart.esm.js
// dist/chart.mjs
// helpers/*.js
{
input: inputESM,
Expand All @@ -73,7 +73,8 @@ module.exports = [
],
output: {
dir: './',
chunkFileNames: 'dist/chunks/[name].js',
chunkFileNames: 'dist/chunks/[name].mjs',
entryFileNames: '[name].mjs',
banner,
format: 'esm',
indent: false,
Expand Down

0 comments on commit 76c9e7f

Please sign in to comment.