-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.mjs
More file actions
56 lines (48 loc) · 1.45 KB
/
build.mjs
File metadata and controls
56 lines (48 loc) · 1.45 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
45
46
47
48
49
50
51
52
53
54
55
56
import * as esbuild from "esbuild";
import { copyFileSync, mkdirSync, existsSync } from "fs";
import path from "path";
const watch = process.argv.includes("--watch");
/** Files to copy verbatim into dist/. */
const staticFiles = [
["manifest.json", "manifest.json"],
["src/popup/popup.html", "popup/popup.html"],
["src/popup/popup.css", "popup/popup.css"],
["src/options/options.html", "options/options.html"],
["src/Logo.svg", "popup/Logo.svg"],
];
function ensureDir(dir) {
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
}
function copyStatic() {
for (const [src, dest] of staticFiles) {
const outPath = path.join("dist", dest);
ensureDir(path.dirname(outPath));
copyFileSync(src, outPath);
}
console.log("[build] static files copied");
}
const entryPoints = [
{ in: "src/background.ts", out: "background" },
{ in: "src/content.ts", out: "content" },
{ in: "src/popup/popup.ts", out: "popup/popup" },
{ in: "src/options/options.ts", out: "options/options" },
];
/** @type {import("esbuild").BuildOptions} */
const opts = {
entryPoints: entryPoints.map((e) => ({ in: e.in, out: e.out })),
bundle: true,
outdir: "dist",
format: "iife",
target: "chrome120",
minify: !watch,
sourcemap: watch ? "inline" : false,
logLevel: "info",
};
copyStatic();
if (watch) {
const ctx = await esbuild.context(opts);
await ctx.watch();
console.log("[build] watching for changes…");
} else {
await esbuild.build(opts);
}