-
-
Notifications
You must be signed in to change notification settings - Fork 240
/
rollup.config.js
116 lines (114 loc) · 2.82 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import nodent from "rollup-plugin-nodent";
import babel from "@rollup/plugin-babel";
import cleanup from "rollup-plugin-cleanup";
import terser from "@rollup/plugin-terser";
import pkg from "./package.json" assert { type: "json" };
import gzipPlugin from "rollup-plugin-gzip";
import analyze from "rollup-plugin-analyzer";
import sizes from "rollup-plugin-sizes";
import serve from "rollup-plugin-serve";
import livereload from "rollup-plugin-livereload";
// Library Name
const libName = "autoComplete";
// Build Environment
const isProduction = process.env.NODE_ENV === "production";
// Library Max. Size Allowed
const limitBytes = 3 * 1024 * 1024;
// Library Size Analyzer
const onAnalysis = ({ bundleSize }) => {
if (bundleSize < limitBytes) return;
console.log(`Bundle size exceeds ${limitBytes} bytes: ${bundleSize} bytes`);
return process.exit(1);
};
// Rollup Config.
export default [
{
input: "src/autoComplete.js",
output: [
{
file: `./${pkg.browser}`,
name: libName,
format: "umd",
},
{
file: "./docs/demo/js/autoComplete.min.js",
name: libName,
format: "umd",
// sourcemap: isProduction ? false : "inline",
},
],
plugins: [
nodent({
es7: true,
promises: true,
// sourcemap: isProduction ? false : true,
noRuntime: true,
es6target: true,
}),
babel({
babelHelpers: "bundled",
exclude: "node_modules/**",
presets: ["@babel/preset-env"],
}),
cleanup(),
terser({
compress: {
drop_console: true,
},
toplevel: true,
}),
gzipPlugin.default(),
],
},
{
input: "src/autoComplete.js",
output: [
{
file: `./${pkg.main}`,
name: libName,
format: "umd",
},
{
file: "./docs/demo/js/autoComplete.js",
name: libName,
format: "umd",
// sourcemap: isProduction ? false : "inline",
},
],
plugins: [
nodent({
es7: true,
promises: true,
// sourcemap: isProduction ? false : true,
noRuntime: true,
es6target: true,
}),
babel({
babelHelpers: "bundled",
exclude: "node_modules/**",
presets: ["@babel/preset-env"],
}),
cleanup(),
gzipPlugin.default(),
// Analyzer
analyze({
onAnalysis,
summaryOnly: true,
showExports: true,
}),
sizes(),
// Server
!isProduction &&
serve({
open: true,
openPage: "./docs/demo/index.html",
host: "localhost",
port: 8000,
verbose: true,
contentBase: "./docs/demo",
}),
// Live Reload
!isProduction && livereload({ watch: ["./docs/demo/", "./src/"] }),
],
},
];