-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathbuild.ts
66 lines (59 loc) · 1.45 KB
/
build.ts
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 * as esbuild from "esbuild";
import { copy } from "esbuild-plugin-copy";
const buildMode = "--build";
const watchMode = "--watch";
const helpString = `Mode must be provided as one of ${buildMode} or ${watchMode}`;
const args = process.argv.splice(2);
if (args.length !== 1) {
console.error(helpString);
process.exit(1);
}
const mode = args[0];
const buildOptions: esbuild.BuildOptions = {
entryPoints: {
index: "src/index.ts",
},
bundle: true,
write: true,
sourcemap: "linked",
outdir: "./build/",
assetNames: "[dir]/[name]-[hash]",
preserveSymlinks: true,
loader: {
".svg": "file",
".png": "file",
".jpg": "file",
".glb": "file",
".hdr": "file",
},
outbase: "./src/",
sourceRoot: "./src/",
publicPath: "/web-client/",
plugins: [
copy({
resolveFrom: "cwd",
assets: {
from: ["./public/**/*"],
to: ["./build/"],
},
}),
],
};
switch (mode) {
case buildMode:
esbuild.build(buildOptions).catch(() => process.exit(1));
break;
case watchMode:
esbuild
.context({
...buildOptions,
banner: {
js: ` (() => new WebSocket((window.location.protocol === "https:" ? "wss://" : "ws://")+window.location.host+'/web-client-build').addEventListener('message', () => location.reload()))();`,
},
})
.then((context) => context.watch())
.catch(() => process.exit(1));
break;
default:
console.error(helpString);
}