-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
121 lines (108 loc) · 2.62 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
117
118
119
120
121
import {
promises as fs
} from "fs";
import babel from "@rollup/plugin-babel";
import json from "@rollup/plugin-json";
import commonjs from "@rollup/plugin-commonjs";
import progress from "rollup-plugin-progress";
import visualizer from "rollup-plugin-visualizer";
import del from "rollup-plugin-delete";
import filesize from "rollup-plugin-filesize";
import analyzer from "rollup-plugin-analyzer";
import {
terser
} from "rollup-plugin-terser";
import resolve from "@rollup/plugin-node-resolve";
import packageJson from "./package.json";
const packageName = packageJson.name;
/**
* @private
*/
const getLicense = async() => {
const license = await fs.readFile("./license.md", "utf8");
return `/**\n${`@license\n${license.replace(/^.*\n\n|\n$/g, "")}`.replace(/^/gm, " * ")}\n */`;
};
const outputs = Object.fromEntries(Object.entries({
browser: "iife",
node: "cjs"
}).map(([bundleName, format]) => [
bundleName,
[
{
banner: bundleName === "browser" ? getLicense : null,
exports: "auto",
file: `./build/index.${bundleName}.${format === "cjs" ? "cjs" : "js"}`,
format,
name: packageName.replace(/^@(.*?)\W/, ""),
preferConst: true,
sourcemap: bundleName === "browser",
sourcemapExcludeSources: true
}
]
]));
outputs.browser.push({
...outputs.browser[0],
file: "./build/index.browser.min.js",
plugins: [terser()]
});
const allBundles = Object.keys(outputs);
const bundlePlugins = {
browser: [
resolve({
browser: true,
preferBuiltins: false
})
],
node: []
};
/**
* @private
*/
export default (options) => {
const bundles = Object.keys(options)
.filter((option) => option.startsWith("config") && option !== "config")
.map((option) => option.replace("config", "").toLocaleLowerCase())
.filter((bundleName) => allBundles.includes(bundleName));
const activeBundles = bundles.length
? allBundles.filter((config) => bundles.includes(config))
: allBundles;
const {
configVerbose: verbose
} = options;
return activeBundles.map((bundleName) => ({
input: "./source/index.js",
output: outputs[bundleName],
plugins: [
del({
targets: `./build/index.${bundleName}.js`
}),
babel({
babelHelpers: "bundled"
}),
commonjs(),
json(),
progress(),
visualizer({
filename: `./stats/${bundleName}/sun.html`,
template: "sunburst"
}),
visualizer({
filename: `./stats/${bundleName}/tree.html`,
template: "treemap"
}),
visualizer({
filename: `./stats/${bundleName}/net.html`,
template: "network"
}),
filesize(),
...verbose
? [
analyzer({
summaryOnly: true
})
]
: [],
...bundlePlugins[bundleName]
]
}));
};