Skip to content

Commit bc97987

Browse files
committed
Build ESM, CJS and UMD version with Rollup
1 parent f21aa6b commit bc97987

File tree

3 files changed

+307
-10
lines changed

3 files changed

+307
-10
lines changed

package.json

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,23 @@
2222
"package.json",
2323
"README.md"
2424
],
25-
"main": "dist/chartist-plugin-tooltip.js",
26-
"browser": "dist/chartist-plugin-tooltip.js",
25+
"main": "./src/scripts/chartist-plugin-tooltip.ts",
26+
"types": "./dist/chartist-plugin-tooltip.d.ts",
27+
"style": "./dist/chartist-plugin-tooltip.css",
28+
"browser": "./dist/chartist-plugin-tooltip.js",
29+
"unpkg": "./dist/chartist-plugin-tooltip.umd.js",
30+
"publishConfig": {
31+
"main": "./dist/chartist-plugin-tooltip.cjs",
32+
"module": "./dist/chartist-plugin-tooltip.js",
33+
"exports": {
34+
".": {
35+
"require": "./dist/chartist-plugin-tooltip.cjs",
36+
"import": "./dist/chartist-plugin-tooltip.js"
37+
},
38+
"./dist/*": "./dist/*"
39+
},
40+
"directory": "package"
41+
},
2742
"licenses": [
2843
{
2944
"type": "MIT",
@@ -35,6 +50,8 @@
3550
},
3651
"devDependencies": {
3752
"@eslint/js": "^10.0.1",
53+
"@rollup/plugin-terser": "^1.0.0",
54+
"@rollup/plugin-typescript": "^12.3.0",
3855
"copyfiles": "^2.4.1",
3956
"del": "^8.0.1",
4057
"del-cli": "^7.0.0",
@@ -43,24 +60,25 @@
4360
"globals": "^17.4.0",
4461
"minify": "^15.2.0",
4562
"prettier": "^3.8.1",
63+
"rollup": "^4.60.0",
4664
"sass": "^1.98.0",
4765
"stylelint": "^17.5.0",
4866
"stylelint-config-standard-scss": "^17.0.0",
4967
"stylelint-scss": "^7.0.0",
5068
"terser": "^5.46.1",
69+
"tslib": "^2.8.1",
5170
"typescript": "^5.9.3",
5271
"typescript-eslint": "^8.57.1"
5372
},
5473
"scripts": {
5574
"clean": "del ./dist ./.tmp",
5675
"build": "yarn clean && yarn build:styles && yarn build:scripts",
57-
"build:scripts": "tsc && terser -o dist/chartist-plugin-tooltip.min.js dist/chartist-plugin-tooltip.js",
58-
"build:styles": "sass --no-source-map --style compressed src/styles:dist",
76+
"build:scripts": "rollup -c",
77+
"build:styles": "sass --style compressed src/styles:dist",
5978
"format": "prettier --write 'src/**/*.ts'",
6079
"lint": "yarn lint:scripts && yarn lint:styles",
6180
"lint:scripts": "eslint 'src/scripts/**/*.ts'",
62-
"lint:styles": "stylelint 'src/styles/**/*.scss'",
63-
"prepare": "yarn build"
81+
"lint:styles": "stylelint 'src/styles/**/*.scss'"
6482
},
6583
"license": "MIT"
6684
}

rollup.config.mjs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import pkg from './package.json' with {type: "json"};
2+
import terser from '@rollup/plugin-terser';
3+
import typescript from '@rollup/plugin-typescript';
4+
5+
export default {
6+
external: ['chartist'],
7+
input: pkg.main,
8+
output: [
9+
{
10+
file: pkg.publishConfig.main,
11+
format: 'cjs',
12+
globals: {
13+
chartist: 'Chartist'
14+
},
15+
sourcemap: true
16+
},
17+
{
18+
file: pkg.publishConfig.module,
19+
format: 'es',
20+
globals: {
21+
chartist: 'Chartist'
22+
},
23+
sourcemap: true
24+
},
25+
{
26+
file: pkg.unpkg,
27+
format: 'umd',
28+
name: 'ChartistPluginTooltip',
29+
globals: {
30+
chartist: 'Chartist'
31+
},
32+
sourcemap: true
33+
}
34+
],
35+
plugins: [typescript(), terser()]
36+
};

0 commit comments

Comments
 (0)