-
Notifications
You must be signed in to change notification settings - Fork 168
/
rollup.config.js
45 lines (40 loc) · 1.18 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
import typescript from "@rollup/plugin-typescript";
import { terser } from "rollup-plugin-terser";
import livereload from "rollup-plugin-livereload";
import serve from "rollup-plugin-serve";
import pkg from "./package.json";
const input = "./src/index.ts";
const commonTSPluginOptions = {
lib: ["es5", "es6", "ESNext", "dom"],
};
const umdConfig = (min, plugins = []) => ({
input,
output: {
name: pkg.umdName,
file: min ? pkg.browser.replace(".js", ".min.js") : pkg.browser,
exports: "default",
format: "umd",
},
plugins: [typescript(commonTSPluginOptions), ...(min ? [terser()] : []), ...plugins],
});
const esConfig = (min, plugins = []) => ({
input,
output: {
file: min ? pkg.module.replace(".js", ".min.js") : pkg.module,
format: "es",
},
plugins: [typescript({ ...commonTSPluginOptions, target: "es6" }), ...(min ? [terser()] : []), ...plugins],
});
export default process.env.BUILD === "watch"
? [
umdConfig(false, [
serve({
open: true,
contentBase: ".",
}),
livereload({
watch: "dist",
}),
]),
]
: [esConfig(true), esConfig(false), umdConfig(true), umdConfig(false)];