-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.mjs
56 lines (48 loc) · 1.27 KB
/
build.mjs
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
import { build, context } from "esbuild";
const isProduction = process.env.NODE_ENV === "production";
const baseConfig = {
bundle: true,
minify: isProduction,
sourcemap: !isProduction,
};
/** @type {import('esbuild').BuildOptions} */
const extensionConfig = {
...baseConfig,
platform: "node",
mainFields: ["module", "main"],
format: "cjs",
entryPoints: ["./src/extension.ts"],
outdir: "./out",
external: ["vscode"],
};
/** @type {import('esbuild').BuildOptions} */
const appConfig = {
...baseConfig,
target: "es2020",
format: "esm",
// entryPoints: ["./src/app/main.js"],
entryPoints: ["./src/app/main.mts"],
outdir: "./out/app",
platform: "browser",
};
try {
if (process.argv.includes("--watch")) {
console.log("[watch] build started");
await (await context(extensionConfig)).watch();
await (await context(appConfig)).watch();
console.log("[watch] build finished");
} else {
await build(extensionConfig);
await build(appConfig);
}
} catch (error) {
if (error) {
error.errors?.forEach((error) =>
console.error(
`> ${error.location.file}:${error.location.line}:${error.location.column}: error: ${error.text}`
)
) || console.log(error);
}
process.stderr.write(error.stderr);
process.exit(1);
}