-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.mjs
More file actions
44 lines (40 loc) · 1.38 KB
/
Copy pathbuild.mjs
File metadata and controls
44 lines (40 loc) · 1.38 KB
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
// Bundles the three MV3 entry points. A bundle step is mandatory because MV3
// cannot load bare ESM specifiers like @revertwtf/client directly.
import { mkdir } from "node:fs/promises";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import { rollup, watch } from "rollup";
const entries = {
background: "src/background.js",
content: "src/content.js",
options: "src/options.js",
popup: "src/popup.js",
};
/** @type {Array<{ input: string, plugins: import("rollup").Plugin[], output: import("rollup").OutputOptions }>} */
const configs = Object.entries(entries).map(([name, input]) => ({
input,
plugins: [nodeResolve({ browser: true })],
output: {
file: `build/${name}.js`,
format: "esm",
sourcemap: false,
},
}));
if (process.argv.includes("--watch")) {
const watcher = watch(/** @type {import("rollup").RollupWatchOptions[]} */ (configs));
watcher.on("event", (event) => {
if (event.code === "BUNDLE_END") console.log(`built -> ${event.output[0]}`);
if (event.code === "ERROR") console.error(event.error);
});
console.log("watching... (ctrl-c to stop)");
} else {
await mkdir("build", { recursive: true });
for (const config of configs) {
const bundle = await rollup({
input: config.input,
plugins: config.plugins,
});
await bundle.write(config.output);
await bundle.close();
}
console.log("built -> build/");
}