forked from mml-io/mml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
52 lines (45 loc) · 1.04 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
const esbuild = require("esbuild");
const { copy } = require("esbuild-plugin-copy");
const buildMode = "--build";
const watchMode = "--watch";
const helpString = `Mode must be provided as one of ${buildMode} or ${watchMode}`;
const buildOptions = {
entryPoints: ["src/index.ts"],
write: true,
bundle: true,
format: "cjs",
outdir: "build",
platform: "node",
packages: "external",
sourcemap: true,
target: "node14",
plugins: [
copy({
resolveFrom: "cwd",
assets: {
from: ["./types-src/**/*"],
to: ["./build/"],
keepStructure: true,
},
}),
],
};
const args = process.argv.splice(2);
if (args.length !== 1) {
console.error(helpString);
process.exit(1);
}
const mode = args[0];
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);
}