-
Notifications
You must be signed in to change notification settings - Fork 2
/
rollup.config.js
97 lines (93 loc) · 2.05 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
94
95
96
97
const path = require('path');
const commonjs = require('@rollup/plugin-commonjs');
const { nodeResolve } = require('@rollup/plugin-node-resolve');
const { default: babel } = require('@rollup/plugin-babel');
const replace = require('@rollup/plugin-replace');
const json = require('@rollup/plugin-json');
const clear = require('rollup-plugin-clear');
const { terser } = require('rollup-plugin-terser');
const babelConfig = require('./babel.config');
const __DEV__ = !!process.env.ROLLUP_WATCH;
const extensions = ['.ts', '.tsx', '.js', '.jsx', '.json'];
function generateConfig(
{
input,
filename,
format = 'umd',
min = false,
}
) {
return {
input,
output: [
{
file: filename,
format,
sourcemap: true,
name: 'DecimalEval',
exports: 'named'
},
],
watch: {
include: 'src/**',
exclude: 'node_modules/**'
},
plugins: [
clear({ targets: ['dist'] }),
json(),
commonjs(),
babel({
...babelConfig,
babelHelpers: 'runtime',
extensions
}),
nodeResolve({
extensions
}),
replace({
__VERSION__: `"${require('./package.json').version}"`
}),
min && terser({
output: {
comments: false
}
}),
].filter(Boolean)
};
}
module.exports = [
// index.js
generateConfig({
input: 'src/index.ts',
filename: 'dist/index.js'
}),
// index.min.js
generateConfig({
input: 'src/index.ts',
filename: 'dist/index.min.js',
min: true
}),
// index.esm.js
!__DEV__ && generateConfig({
input: 'src/index.ts',
filename: 'dist/index.esm.js',
format: 'esm',
}),
// pure.js
!__DEV__ && generateConfig({
input: 'src/pure.ts',
filename: 'dist/pure.js'
}),
// pure.min.js
!__DEV__ && generateConfig({
input: 'src/pure.ts',
filename: 'dist/pure.min.js',
min: true
}),
// pure.esm.js
!__DEV__ && generateConfig({
input: 'src/pure.ts',
filename: 'dist/pure.esm.js',
format: 'esm',
})
].filter(Boolean);