-
Notifications
You must be signed in to change notification settings - Fork 2
/
rollup.config.js
89 lines (83 loc) · 2.11 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
import { readFileSync } from 'fs';
import ts from 'rollup-plugin-typescript2';
import resolve from 'rollup-plugin-node-resolve';
import commonJS from 'rollup-plugin-commonjs';
import uglify from 'rollup-plugin-uglify';
const pkg = JSON.parse(readFileSync('package.json', 'utf-8'));
const { mod, minify } = process.env;
function when(predicate, opts) {
return predicate ? opts : {};
}
function output(target, format, opts = {}) {
return {
input: `src/${pkg.name}.ts`,
output: { ...{ file: `dist/${mod}/${pkg.name}${minify ? '.min' : ''}.js`, format, name: pkg.name }, ...opts },
plugins: [
resolve(),
commonJS({
include: 'node_modules/**'
}),
ts({
tsconfig: `configs/tsconfig-build-${mod}.json`,
tsconfigOverride: {
compilerOptions: {
target,
module: target === 'es2017' ? 'es2015' : target,
declaration: !minify
}
},
cacheRoot: `.rollupcache/${mod}`
}),
when(
minify,
uglify({
compress: {
sequences: true,
dead_code: true,
conditionals: true,
booleans: true,
unused: true,
if_return: true,
join_vars: true,
drop_console: true
},
output: {
comments: false
}
})
)
],
external: [
// add any peerDependencies here that you don't want included in the bundle, for example:
//'aurelia-framework'
]
};
}
let config;
switch (mod) {
case 'amd':
config = output('es2015', 'amd', { amd: { id: pkg.name } });
break;
case 'commonjs':
config = output('es2015', 'cjs');
break;
case 'es2015':
config = output('es2015', 'es');
break;
case 'es2017':
config = output('es2017', 'es');
break;
case 'esnext':
config = output('esnext', 'es');
break;
case 'native-modules':
config = output('es2015', 'es');
break;
case 'system':
config = output('es2015', 'system');
break;
case 'umd':
config = output('es2015', 'umd');
break;
}
export default config;