-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathbuild.ts
40 lines (33 loc) · 843 Bytes
/
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
import * as esbuild from "esbuild";
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: ["src/index.ts"],
outdir: "./build",
bundle: true,
format: "esm",
packages: "external",
sourcemap: true,
platform: "node",
target: "es2020",
};
switch (mode) {
case buildMode:
esbuild.build(buildOptions).catch(() => process.exit(1));
break;
case watchMode:
esbuild
.context({ ...buildOptions })
.then((context) => context.watch())
.catch(() => process.exit(1));
break;
default:
console.error(helpString);
}