-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathesbuilder.js
More file actions
62 lines (56 loc) · 1.56 KB
/
esbuilder.js
File metadata and controls
62 lines (56 loc) · 1.56 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
// crankshaft's build script. uses esbuild, which is a fast js build tool written in go.
const esbuild = require("esbuild");
const fs = require("node:fs");
const args = process.argv.filter(a => a.startsWith("--"))
const building = args.includes("--build")
const watching = args.includes("--watch")
const metaFile = args.includes("--meta")
console.log("building(minifying):", building, "watching:", watching)
fs.rmSync("app/main.js", { force: true });
fs.rmSync("app/preload.js", { force: true });
fs.rmSync("app/socialpreload.js", { force: true });
/**
* @type {import('esbuild').Plugin}
*/
const buildLogger = {
name: 'build-logger',
setup(build) {
build.onEnd(result => console.log(`build completed with ${result.errors.length} errors`))
},
}
/**
* @type {import('esbuild').BuildOptions}
*/
const buildOptions = {
// keep this manually in-sync!
entryPoints: [
'src/main.ts',
'src/preload.ts',
'src/socialpreload.ts'
],
bundle: true,
minify: building,
sourcemap: building ? false : "inline",
metafile: metaFile,
format: 'cjs',
platform: 'node',
target: ["node14", "chrome89"], // electron 12.2.3
outdir: 'app',
tsconfig: 'tsconfig.json',
external: ["electron"]
}
/**
* @param {import('esbuild').BuildOptions} extraOptions
*/
async function watch(extraOptions) {
const ctx = await esbuild.context({ ...buildOptions, ...extraOptions })
await ctx.watch()
}
if (watching) {
watch({ plugins: [ buildLogger ] })
} else {
const result = esbuild.buildSync(buildOptions)
if (metaFile) {
fs.writeFileSync("metafile.json", JSON.stringify(result.metafile))
}
}