-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-vscode.mjs
More file actions
90 lines (78 loc) · 2.18 KB
/
build-vscode.mjs
File metadata and controls
90 lines (78 loc) · 2.18 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env node
import esbuild from "esbuild";
import path from "path";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const isWatch = process.argv.includes("--watch");
// Common options
const commonOptions = {
bundle: true,
sourcemap: true,
minify: !isWatch,
logLevel: "info",
};
// Build extension (Node.js environment)
const extensionOptions = {
...commonOptions,
entryPoints: [
path.join(__dirname, "../platforms/vscode/src/extension.ts"),
],
outfile: path.join(__dirname, "../platforms/vscode/dist/extension.js"),
format: "cjs",
platform: "node",
external: ["vscode"],
target: "node16",
};
// Build webview (Browser environment)
const webviewOptions = {
...commonOptions,
entryPoints: [
path.join(__dirname, "../platforms/vscode/src/webview.tsx"),
],
outfile: path.join(__dirname, "../platforms/vscode/dist/webview.js"),
format: "iife",
platform: "browser",
target: ["es2020", "chrome90", "firefox90"],
loader: {
".svg": "dataurl",
".png": "dataurl",
".jpg": "dataurl",
".jpeg": "dataurl",
".woff": "dataurl",
".woff2": "dataurl",
".ttf": "dataurl",
".eot": "dataurl",
},
define: {
"process.env.NODE_ENV": '"production"',
},
};
async function build() {
try {
if (isWatch) {
const ctxExtension = await esbuild.context(extensionOptions);
const ctxWebview = await esbuild.context(webviewOptions);
await Promise.all([
ctxExtension.watch(),
ctxWebview.watch(),
]);
console.log("Watching for changes...");
} else {
await Promise.all([
esbuild.build(extensionOptions),
esbuild.build(webviewOptions),
]);
// Copy CSS file
const fs = await import("fs/promises");
const cssSource = path.join(__dirname, "../packages/learningmap/dist/index.css");
const cssTarget = path.join(__dirname, "../platforms/vscode/dist/webview.css");
await fs.copyFile(cssSource, cssTarget);
console.log("Build complete!");
}
} catch (error) {
console.error("Build failed:", error);
process.exit(1);
}
}
build();