-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathesbuild.mjs
More file actions
55 lines (50 loc) · 1.31 KB
/
Copy pathesbuild.mjs
File metadata and controls
55 lines (50 loc) · 1.31 KB
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
import * as esbuild from "esbuild";
const production = process.argv.includes("--production");
const watch = process.argv.includes("--watch");
/** @type {esbuild.BuildOptions} */
const extensionConfig = {
entryPoints: ["src/extension.ts"],
bundle: true,
outfile: "dist/extension.js",
external: ["vscode"],
format: "cjs",
platform: "node",
sourcemap: !production,
minify: production,
treeShaking: true,
};
/** @type {esbuild.BuildOptions} */
const webviewConfig = {
entryPoints: ["src/webview/main.ts"],
bundle: true,
outfile: "dist/webview.js",
format: "iife",
platform: "browser",
sourcemap: !production,
minify: production,
treeShaking: true,
// KaTeX 需要的 CSS 作为文件复制
loader: {
".woff2": "file",
".woff": "file",
".ttf": "file",
},
};
async function main() {
if (watch) {
const extCtx = await esbuild.context(extensionConfig);
const webCtx = await esbuild.context(webviewConfig);
await Promise.all([extCtx.watch(), webCtx.watch()]);
console.log("[watch] Build started...");
} else {
await Promise.all([
esbuild.build(extensionConfig),
esbuild.build(webviewConfig),
]);
console.log(production ? "[prod] Build complete." : "[dev] Build complete.");
}
}
main().catch((e) => {
console.error(e);
process.exit(1);
});