forked from leonvogt/hotwire-dev-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
62 lines (54 loc) · 1.58 KB
/
build.js
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
const esbuild = require("esbuild")
const fs = require("fs-extra")
const path = require("path")
const mustache = require("mustache")
const nodeEnv = process.env.NODE_ENV
const browser = process.argv[3] || "chrome"
const production = nodeEnv === "production"
const outputPath = path.join(__dirname, "public", "manifest.json")
const templatePath = path.join(__dirname, "manifest.template.json")
const browserSpecificSettings = {
chrome: {
browser_specific_settings: false,
},
firefox: {
browser_specific_settings: true,
},
safari: {
browser_specific_settings: false,
},
}
const esbuildConfig = {
entryPoints: ["./src/content.js", "./src/popup.js", "./src/hotwire_dev_tools_inject_script.js"],
bundle: true,
minify: production,
sourcemap: !production,
target: ["chrome88", "firefox109", "safari15"],
outdir: "./public/dist",
define: {
"process.env.NODE_ENV": `"${nodeEnv}"`,
},
}
async function generateManifest() {
try {
const template = await fs.readFile(templatePath, "utf8")
const output = mustache.render(template, browserSpecificSettings[browser])
await fs.writeFile(outputPath, output)
console.log(`Generated manifest.json for ${browser}`)
} catch (err) {
console.error("Error generating manifest file:", err)
}
}
const buildAndWatch = async () => {
const context = await esbuild.context({ ...esbuildConfig, logLevel: "info" })
context.watch()
}
async function buildProject() {
await generateManifest()
if (process.argv.includes("--watch")) {
buildAndWatch()
} else {
esbuild.build(esbuildConfig)
}
}
buildProject()