-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
50 lines (43 loc) · 1.06 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
const esbuild = require("esbuild");
const production = process.argv.findIndex((argItem) => argItem === "--mode=production") >= 0;
const onRebuild = (context) => {
return async (err, res) => {
if (err) {
return console.error(`[${context}]: Rebuild failed`, err);
}
console.log(`[${context}]: Rebuild succeeded, warnings:`, res.warnings);
};
};
const server = {
entryPoints: [`server/server.ts`],
outfile: `dist/server.js`,
platform: "node",
target: ["node16"],
format: "cjs",
};
const client = {
entryPoints: [`client/client.ts`],
outfile: `dist/client.js`,
platform: "browser",
target: ["chrome93"],
format: "iife",
};
const nui = {
...client,
entryPoints: [`nui/nui.ts`],
outfile: `dist/nui.js`,
};
for (const context of [server, client, nui]) {
esbuild
.build({
...context,
bundle: true,
watch: production
? false
: {
onRebuild: onRebuild(context),
},
})
.then(() => console.log(`[${context.outfile}]: Built successfully!`))
.catch(() => process.exit(1));
}