-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathesbuild.config.dev.mjs
More file actions
66 lines (56 loc) · 1.9 KB
/
Copy pathesbuild.config.dev.mjs
File metadata and controls
66 lines (56 loc) · 1.9 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
57
58
59
60
61
62
63
64
65
66
import { build } from "esbuild";
import { mkdir, copyFile, rm } from "fs/promises";
import { resolve, dirname } from "path";
const targets = new Set(["chrome", "firefox"]);
const arg = process.argv[2] ?? "all";
const buildTargets = arg === "all" ? Array.from(targets) : [arg];
const entryPoints = {
background: "src/background.ts",
"content-script": "src/content-script.ts",
"page-script": "src/page-script.ts",
popup: "src/popup/popup.ts"
};
async function ensureDir(path) {
await mkdir(path, { recursive: true });
}
async function copyStatic(targetDir, manifestFile) {
await copyFile(manifestFile, resolve(targetDir, "manifest.json"));
await copyFile("src/popup/popup.html", resolve(targetDir, "popup.html"));
await copyFile("src/popup/popup.css", resolve(targetDir, "popup.css"));
await copyFile("src/views/installed.html", resolve(targetDir, "installed.html"));
await copyFile("src/views/updated.html", resolve(targetDir, "updated.html"));
await copyFile("src/views/installed-script.js", resolve(targetDir, "installed-script.js"));
await copyFile("src/views/updated-script.js", resolve(targetDir, "updated-script.js"));
}
async function buildTarget(target) {
if (!targets.has(target)) {
throw new Error(`Unknown build target: ${target}`);
}
const outdir = resolve("dist", target);
await rm(outdir, { recursive: true, force: true });
await ensureDir(outdir);
await build({
entryPoints,
outdir,
bundle: true,
minify: false,
sourcemap: false,
platform: "browser",
target: "es2020",
format: "iife",
define: {
"process.env.NODE_ENV": '"development"',
"__DEV__": "true" // Development için debug log'ları açık
}
});
await copyStatic(outdir, `manifest.${target}.json`);
}
async function run() {
for (const target of buildTargets) {
await buildTarget(target);
}
}
run().catch((error) => {
console.error(error);
process.exit(1);
});