-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.mjs
More file actions
52 lines (43 loc) · 1.45 KB
/
build.mjs
File metadata and controls
52 lines (43 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
import * as esbuild from "esbuild";
import { cpSync, mkdirSync } from "fs";
const watch = process.argv.includes("--watch");
mkdirSync("dist", { recursive: true });
// Copy static files to dist
cpSync("static", "dist", { recursive: true });
cpSync("src/styles", "dist/styles", { recursive: true });
// Chrome reads _locales from the extension root for manifest __MSG__ resolution.
cpSync("src/_locales", "dist/_locales", { recursive: true });
const sharedOptions = {
bundle: true,
format: "iife",
target: "chrome120",
minify: !watch,
};
const ctx = await esbuild.context({
...sharedOptions,
entryPoints: ["src/content.ts"],
outfile: "dist/content.js",
});
const optionsCtx = await esbuild.context({
...sharedOptions,
entryPoints: ["src/options.ts"],
outfile: "dist/options.js",
});
const swCtx = await esbuild.context({
...sharedOptions,
entryPoints: ["src/service-worker.ts"],
outfile: "dist/service-worker.js",
});
const earlyCtx = await esbuild.context({
...sharedOptions,
entryPoints: ["src/early-sort-redirect.ts"],
outfile: "dist/early-sort-redirect.js",
});
if (watch) {
await Promise.all([ctx.watch(), optionsCtx.watch(), swCtx.watch(), earlyCtx.watch()]);
console.log("Watching for changes...");
} else {
await Promise.all([ctx.rebuild(), optionsCtx.rebuild(), swCtx.rebuild(), earlyCtx.rebuild()]);
await Promise.all([ctx.dispose(), optionsCtx.dispose(), swCtx.dispose(), earlyCtx.dispose()]);
console.log("Build complete.");
}