-
Notifications
You must be signed in to change notification settings - Fork 329
/
rollup.config.js
93 lines (88 loc) · 2.16 KB
/
rollup.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import commonjs from '@rollup/plugin-commonjs'
import cleanup from 'rollup-plugin-cleanup'
import json from '@rollup/plugin-json'
import resolve from '@rollup/plugin-node-resolve'
import swc from '@rollup/plugin-swc'
import terser from '@rollup/plugin-terser'
import { readFileSync } from 'fs'
const pkg = JSON.parse(readFileSync('./package.json'))
const dependencies = Object.keys(pkg.dependencies)
const peerDependencies = Object.keys(pkg.peerDependencies)
const allDependencies = dependencies.concat(peerDependencies)
const banner = `/*!
* ${pkg.name} v${pkg.version}
* ${pkg.homepage}${pkg.version}/
* (c) 2016-${new Date(process.env.SOURCE_DATE_EPOCH ? process.env.SOURCE_DATE_EPOCH * 1000 : new Date().getTime()).getFullYear()} chartjs-plugin-zoom Contributors
* Released under the MIT License
*/`
const name = 'ChartZoom'
const globals = {
'chart.js': 'Chart',
'chart.js/helpers': 'Chart.helpers',
hammerjs: 'Hammer',
}
allDependencies.push('chart.js/helpers')
const plugins = (minify) => [
commonjs({
include: 'node_modules/**',
}),
json(),
resolve({ extensions: ['.js', '.ts'] }),
swc({
jsc: {
parser: {
syntax: 'typescript',
tsx: false,
},
target: 'es2022',
},
module: {
type: 'es6',
},
sourceMaps: true,
}),
minify ? terser({ output: { comments: 'some' } }) : cleanup({ comments: ['some'], extensions: ['js', 'ts'] }),
]
export default [
{
input: 'src/index.umd.ts',
output: {
name,
file: `dist/${pkg.name}.js`,
banner,
format: 'umd',
indent: false,
globals,
sourcemap: true,
},
plugins: plugins(),
external: allDependencies,
},
{
input: 'src/index.umd.ts',
output: {
name,
file: `dist/${pkg.name}.min.js`,
banner,
format: 'umd',
indent: false,
globals,
sourcemap: true,
},
plugins: plugins(true),
external: allDependencies,
},
{
input: 'src/index.ts',
plugins: plugins(),
output: {
name,
file: `dist/${pkg.name}.esm.js`,
banner,
format: 'esm',
indent: false,
sourcemap: true,
},
external: allDependencies,
},
]