-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
85 lines (79 loc) · 2.15 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
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import pkg from './package.json';
import babel from 'rollup-plugin-babel';
import { uglify } from 'rollup-plugin-uglify';
const ensureArray = maybeArr =>
Array.isArray(maybeArr) ? maybeArr : [maybeArr];
const external = Object.keys(pkg.dependencies || {});
const makeExternalPredicate = externalArr => {
if (externalArr.length === 0) {
return () => false;
}
const pattern = new RegExp(`^(${externalArr.join('|')})($|/)`);
return id => pattern.test(id);
};
const createConfig = ({ output, min = false } = {}) => {
return {
input: 'src/index.js',
output: ensureArray(output).map(output => {
output.name = 'EventReporter';
if (min) {
output.file = output.file.replace(/\.js$/, '.min.js');
}
return output
}),
plugins: [
resolve(),
babel({
exclude: 'node_modules/**',
runtimeHelpers: true,
plugins: [
[
'@babel/transform-runtime',
{
useESModules: output.format === 'es'
}
]
]
}),
commonjs(),
min &&
uglify({
compress: {
pure_getters: true,
unsafe: true,
unsafe_comps: true
}
})
].filter(Boolean),
external: makeExternalPredicate(output.format === 'umd' ? [] : external)
};
};
export default [
createConfig({
output: {
file: 'dist/index.umd.js',
format: 'umd'
}
}),
createConfig({
output: {
file: 'dist/index.umd.js',
format: 'umd'
},
min: true
}),
createConfig({
output: {
file: pkg.main,
format: 'cjs'
}
}),
createConfig({
output: {
file: pkg.module,
format: 'es'
}
})
];