-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathrollup.config.js
101 lines (93 loc) · 1.8 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
98
99
100
101
// rollup.config.js
import resolve from "rollup-plugin-node-resolve";
import typescript from "rollup-plugin-typescript2";
import uglify from "rollup-plugin-uglify";
import { minify } from "uglify-es";
const base = {
input: "src/index.ts",
plugins: [resolve()],
};
const CACHE_ROOT = `${require("temp-dir")}/.rpt2_cache_${process.env
.ROLLUP_CONFIG}`;
const browser = {
...base,
output: {
name: "Wobble",
format: "iife",
file: "./dist/wobble.browser.js",
sourcemap: true,
},
plugins: [
...base.plugins,
typescript({
cacheRoot: CACHE_ROOT,
tsconfigOverride: {
compilerOptions: {
declaration: false,
},
},
typescript: require("typescript"),
}),
]
};
const cjs = {
...browser,
output: {
...browser.output,
format: "cjs",
file: browser.output.file.replace("browser", "cjs"),
},
};
const es = {
...base,
output: {
format: "es",
file: "./dist/wobble.es.js",
sourcemap: true
},
plugins: [
...base.plugins,
typescript({
cacheRoot: CACHE_ROOT,
tsconfigOverride: {
compilerOptions: {
module: "esnext",
target: "ES2017",
declaration: false,
},
},
typescript: require("typescript"),
}),
]
};
let config;
switch (process.env.ROLLUP_CONFIG) {
case "cjs":
config = cjs;
break;
case "browser":
config = browser;
break;
case "es":
config = es;
break;
default:
throw new Error("Must set ROLLUP_CONFIG");
}
export default [
config,
addMinifier(config),
];
function addMinifier(config) {
return {
...config,
output: {
...config.output,
file: config.output.file.replace(".js", ".min.js"),
},
plugins: [
...config.plugins,
uglify({}, minify),
],
};
}