-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
81 lines (70 loc) · 2.01 KB
/
Copy pathbuild.js
File metadata and controls
81 lines (70 loc) · 2.01 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import esbuild from "esbuild"
import fs from "fs"
import path from "path"
const OUTPUT_DIR = "distro"
fs.rmSync(OUTPUT_DIR, { recursive: true, force: true })
async function build(targetBrowser) {
const targetDir = `${OUTPUT_DIR}/${targetBrowser}`
if (targetBrowser == "chrome") {
await esbuild.build({
entryPoints: {
background: "src/background.js",
content: "src/content.js",
popup: "src/popup/popup.css",
offscreen: "src/offscreen/offscreen.js",
},
bundle: true,
format: "iife",
target: "chrome116",
outdir: targetDir,
entryNames: "[name]",
loader: {
".css": "css",
".js": "js",
},
sourcemap: false,
minify: false,
})
fs.copyFileSync(
"src/offscreen/offscreen.html",
path.join(targetDir, "offscreen.html")
)
} else {
await esbuild.build({
entryPoints: {
background: "src/background.js",
content: "src/content.js",
popup: "src/popup/popup.css",
},
bundle: true,
format: "iife",
target: "firefox109",
outdir: targetDir,
entryNames: "[name]",
loader: {
".js": "js",
},
sourcemap: false,
minify: false,
})
}
const baseManifest = JSON.parse(fs.readFileSync("src/manifest.base.json"))
const targetManifest = JSON.parse(
fs.readFileSync(`src/manifest.${targetBrowser}.json`)
)
const manifest = { ...baseManifest, ...targetManifest }
fs.writeFileSync(
path.join(targetDir, "manifest.json"),
JSON.stringify(manifest, null, 2)
)
fs.copyFileSync("src/popup/popup.html", path.join(targetDir, "popup.html"))
fs.copyFileSync("src/popup/popup.js", path.join(targetDir, "popup.js"))
fs.mkdirSync(`${OUTPUT_DIR}/${targetBrowser}/assets`, { recursive: true })
fs.copyFileSync(
"src/assets/leitner-logo.png",
path.join(`${OUTPUT_DIR}/${targetBrowser}/assets`, "leitner-logo.png")
)
console.log(`Built ${targetBrowser} distro`)
}
build("firefox")
build("chrome")