forked from NepomukWolf/vscode-ifc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathesbuild.js
More file actions
70 lines (61 loc) · 1.91 KB
/
Copy pathesbuild.js
File metadata and controls
70 lines (61 loc) · 1.91 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const esbuild = require("esbuild");
const fs = require("node:fs/promises");
const watch = process.argv.includes("--watch");
/** The extension host bundle (Node/CommonJS). */
const extensionBuild = {
entryPoints: ["src/extension.ts"],
bundle: true,
platform: "node",
format: "cjs",
target: "node20",
outfile: "out/extension.js",
external: ["vscode"],
sourcemap: true,
minify: false,
sourcesContent: true,
logLevel: "info",
};
/** The webview bundle (browser/ESM): three.js + web-ifc geometry. */
const webviewBuild = {
entryPoints: ["media/viewer/main.ts"],
bundle: true,
platform: "browser",
format: "esm",
target: "es2022",
outfile: "out/webview/viewer.js",
sourcemap: true,
// Minified for packaging (the bundle includes three + web-ifc);
// the sourcemap stays for dev and is excluded from the VSIX via .vscodeignore.
minify: true,
sourcesContent: true,
logLevel: "info",
};
/** WASM assets that must sit beside the webview bundle so it can fetch them. */
const wasmCopies = [[require.resolve("web-ifc/web-ifc.wasm"), "out/webview/web-ifc.wasm"]];
async function copyWasm() {
await fs.mkdir("out/webview", { recursive: true });
for (const [from, to] of wasmCopies) {
await fs.copyFile(from, to);
}
}
async function cleanOutDir() {
await fs.rm("out", { recursive: true, force: true });
}
async function main() {
if (watch) {
const extensionContext = await esbuild.context(extensionBuild);
const webviewContext = await esbuild.context(webviewBuild);
await fs.mkdir("out/webview", { recursive: true });
await Promise.all([extensionContext.watch(), webviewContext.watch()]);
await copyWasm();
console.log("Watching extension + webview bundles...");
return;
}
await cleanOutDir();
await Promise.all([esbuild.build(extensionBuild), esbuild.build(webviewBuild)]);
await copyWasm();
}
main().catch((error) => {
console.error(error);
process.exit(1);
});