-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesbuild.js
56 lines (51 loc) · 1.41 KB
/
esbuild.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
53
54
55
56
// @ts-check: Show errors in this js file
const esbuild = require("esbuild");
const polyfillNode = require("esbuild-plugin-polyfill-node").polyfillNode;
async function main() {
const extensionCtx = await esbuild.context({
entryPoints: ["./src/extension.ts"],
bundle: true,
format: "cjs",
platform: "node",
outfile: "./out/extension.js",
sourcemap: true,
external: ["vscode"],
});
const webviewCtx = await esbuild.context({
entryPoints: ["./src/webview/index.tsx"],
bundle: true,
format: "esm",
platform: "browser",
sourcemap: true,
outfile: "./out/webview.js",
plugins: [
polyfillNode({
polyfills: {
fs: true,
},
// globals: {
// __filename: true,
// __dirname: true,
// }
}),
],
define: {
// Needed for the web environment
// Inject these globals manually as esbuild-plugin-polyfill-node is not doing it so
__filename: JSON.stringify("/index.js"),
__dirname: JSON.stringify("/"),
},
});
// Run both configurations at the same time
if (process.argv.includes("--watch")) {
await extensionCtx.watch();
await webviewCtx.watch();
console.log("Watching files...");
} else {
Promise.all([extensionCtx.rebuild(), webviewCtx.rebuild()]).then(() => {
console.log("Builds completed successfully.");
process.exit(0);
});
}
}
main();