-
Notifications
You must be signed in to change notification settings - Fork 12
/
rollup.config.mjs
79 lines (69 loc) · 2.38 KB
/
rollup.config.mjs
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
import archiver from "archiver";
import fs from "fs";
import process from "process";
import terser from "@rollup/plugin-terser";
const isDevelopment = process.env.BUILD === "development";
export default {
input: "scripts/_index.mjs",
output: {
file: "script.js",
format: "iife",
sourcemap: true,
generatedCode: "es2015",
plugins: [terser({
ecma: 2023,
compress: {
booleans: false,
comparisons: true,
conditionals: false,
drop_console: isDevelopment ? false : ["assert"],
drop_debugger: !isDevelopment,
ecma: 2023,
join_vars: !isDevelopment,
keep_classnames: true,
keep_fargs: true,
keep_fnames: isDevelopment,
keep_infinity: true,
lhs_constants: !isDevelopment,
passes: 2,
sequences: false,
typeofs: false,
},
mangle: isDevelopment ? false : { keep_classnames: true, keep_fnames: false },
format: {
ascii_only: true,
beautify: isDevelopment,
comments: false,
keep_numbers: true,
},
keep_classnames: true,
keep_fnames: isDevelopment,
})],
},
plugins: [{
closeBundle() {
if (isDevelopment) {
return;
}
const start = Date.now();
const output = fs.createWriteStream("module.zip");
const archive = archiver("zip", { zlib: { level: 9 } });
output.on("close", function () {
console.log(`\x1b[32mcreated \x1b[1mmodule.zip\x1b[21m in \x1b[1m${Date.now() - start}ms\x1b[21m\x1b[39m`);
});
archive.on("warning", function (error) {
throw error;
});
archive.on("error", function (error) {
throw error;
});
archive.pipe(output);
for (const name of ["module.json", "script.js", "script.js.map", "style.css", "LICENSE"]) {
archive.append(fs.createReadStream(name), { name });
}
archive.directory("icons", "icons");
archive.directory("lang", "lang");
archive.finalize();
},
}],
};