Skip to content

Commit 43140bc

Browse files
committed
feat: convert to module
1 parent 3eb52a3 commit 43140bc

File tree

4 files changed

+41
-31
lines changed

4 files changed

+41
-31
lines changed

karma.conf.js renamed to karma.conf.cjs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
/* eslint-disable @typescript-eslint/no-var-requires */
12
const istanbul = require('rollup-plugin-istanbul');
23
const json = require('@rollup/plugin-json');
34
const resolve = require('@rollup/plugin-node-resolve').default;
4-
const builds = require('./rollup.config');
55
const yargs = require('yargs');
66
const env = process.env.NODE_ENV;
77

8-
module.exports = function(karma) {
8+
module.exports = async function(karma) {
9+
const builds = (await import('./rollup.config.js')).default;
910
const args = yargs
1011
.option('verbose', {default: false})
1112
.argv;

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+15-7
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,34 @@
11
{
22
"name": "chartjs-plugin-gradient",
3-
"version": "0.5.1",
3+
"version": "0.6.0",
44
"description": "Easy gradient colors for Chart.js",
5-
"main": "dist/chartjs-plugin-gradient.js",
6-
"module": "dist/chartjs-plugin-gradient.esm.js",
5+
"type": "module",
6+
"main": "dist/chartjs-plugin-gradient.esm.js",
7+
"jsdelivr": "dist/dist/chartjs-plugin-gradient.min.js",
8+
"unpkg": "dist/dist/chartjs-plugin-gradient.min.js",
9+
"exports": {
10+
".": {
11+
"types": "./types/index.d.ts",
12+
"import": "./dist/chartjs-plugin-gradient.esm.js"
13+
}
14+
},
715
"types": "./types/index.d.ts",
816
"scripts": {
917
"build": "rollup -c",
10-
"dev": "karma start --auto-watch --no-single-run --browsers chrome",
11-
"dev:ff": "karma start --auto-watch --no-single-run --browsers firefox",
18+
"dev": "karma start ./karma.conf.cjs --auto-watch --no-single-run --browsers chrome",
19+
"dev:ff": "karma start ./karma.conf.cjs --auto-watch --no-single-run --browsers firefox",
1220
"lint": "concurrently --group \"npm:lint-*\"",
1321
"lint-js": "eslint \"test/**/*.js\" \"src/**/*.js\" \"types/**/*.ts\"",
1422
"test": "cross-env NODE_ENV=test concurrently --group \"npm:test-*\"",
15-
"test-karma": "karma start --auto-watch --single-run",
23+
"test-karma": "karma start ./karma.conf.cjs --auto-watch --single-run",
1624
"test-lint": "npm run lint"
1725
},
1826
"repository": {
1927
"type": "git",
2028
"url": "git+https://github.com/kurkle/chartjs-plugin-gradient.git"
2129
},
2230
"files": [
23-
"dist/*.js",
31+
"dist/*",
2432
"types/*.d.ts"
2533
],
2634
"keywords": [

rollup.config.js

+21-20
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
const json = require('@rollup/plugin-json');
2-
const resolve = require('@rollup/plugin-node-resolve').default;
3-
const terser = require('@rollup/plugin-terser').default;
4-
const {name, version, homepage, main, module: _module} = require('./package.json');
1+
import resolve from '@rollup/plugin-node-resolve';
2+
import terser from '@rollup/plugin-terser';
3+
import {readFileSync} from 'fs';
4+
5+
const {name, version, homepage, main} = JSON.parse(readFileSync('./package.json'));
56

67
const banner = `/*!
78
* ${name} v${version}
@@ -20,7 +21,7 @@ const globals = {
2021
'chart.js/helpers': 'Chart.helpers'
2122
};
2223

23-
module.exports = [
24+
export default [
2425
{
2526
input,
2627
plugins: [
@@ -30,6 +31,20 @@ module.exports = [
3031
name,
3132
file: main,
3233
banner,
34+
format: 'esm',
35+
indent: false
36+
},
37+
external
38+
},
39+
{
40+
input,
41+
plugins: [
42+
resolve()
43+
],
44+
output: {
45+
name,
46+
file: main.replace('.esm.js', '.js'),
47+
banner,
3348
format: 'umd',
3449
indent: false,
3550
globals
@@ -48,26 +63,12 @@ module.exports = [
4863
],
4964
output: {
5065
name,
51-
file: main.replace('.js', '.min.js'),
66+
file: main.replace('.esm.js', '.min.js'),
5267
format: 'umd',
5368
sourcemap: true,
5469
indent: false,
5570
globals
5671
},
5772
external
5873
},
59-
{
60-
input,
61-
plugins: [
62-
resolve()
63-
],
64-
output: {
65-
name,
66-
file: main.replace('.js', '.esm.js'),
67-
banner,
68-
format: 'esm',
69-
indent: false
70-
},
71-
external
72-
},
7374
];

0 commit comments

Comments
 (0)