forked from single-spa/single-spa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
97 lines (91 loc) · 2.32 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
import resolve from "rollup-plugin-node-resolve";
import babel from "rollup-plugin-babel";
import commonjs from "rollup-plugin-commonjs";
import analyzer from "rollup-plugin-analyzer";
import replace from "@rollup/plugin-replace";
import packageJson from "./package.json";
const isProduction = process.env.NODE_ENV === "production";
const useAnalyzer = process.env.ANALYZER === "analyzer";
const replaceOpts = {
"process.env.BABEL_ENV": null,
__DEV__: !isProduction,
};
const babelOpts = {
exclude: "node_modules/**",
};
const terserOpts = {
compress: {
passes: 2,
},
output: {
comments(node, comment) {
return comment.value.trim().startsWith("single-spa@");
},
},
};
export default (async () => [
{
input: "./src/single-spa.js",
output: [
{
file: `./lib/umd/single-spa${isProduction ? ".min" : ".dev"}.js`,
format: "umd",
name: "singleSpa",
sourcemap: true,
banner: generateBanner("UMD"),
},
{
file: `./lib/system/single-spa${isProduction ? ".min" : ".dev"}.js`,
format: "system",
sourcemap: true,
banner: generateBanner("SystemJS"),
},
{
file: `./lib/esm/single-spa${isProduction ? ".min" : ".dev"}.js`,
format: "esm",
sourcemap: true,
banner: generateBanner("ESM"),
},
],
plugins: [
replace(replaceOpts),
resolve(),
babel(babelOpts),
commonjs(),
isProduction && (await import("rollup-plugin-terser")).terser(terserOpts),
useAnalyzer && analyzer(),
],
},
{
input: "./src/single-spa.js",
output: {
file: `./lib/es2015/single-spa${isProduction ? ".min" : ".dev"}.js`,
format: "esm",
sourcemap: true,
banner: generateBanner("ES2015"),
},
plugins: [
replace(replaceOpts),
resolve(),
babel(
Object.assign({}, babelOpts, {
envName: "esm",
})
),
commonjs(),
isProduction &&
(await import("rollup-plugin-terser")).terser(
Object.assign({}, terserOpts, {
ecma: 6,
module: true,
})
),
useAnalyzer && analyzer(),
],
},
])();
function generateBanner(format) {
return `/* single-spa@${packageJson.version} - ${format} - ${
isProduction ? "prod" : "dev"
} */`;
}