-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathesbuild.config.mjs
More file actions
52 lines (47 loc) · 1.49 KB
/
Copy pathesbuild.config.mjs
File metadata and controls
52 lines (47 loc) · 1.49 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
import * as esbuild from "esbuild";
import { fileURLToPath } from "node:url";
import { dirname, join } from "node:path";
import { mkdirSync, copyFileSync } from "node:fs";
const here = dirname(fileURLToPath(import.meta.url));
const watch = process.argv.includes("--watch");
// 1. Build Extension Host
const extOptions = {
entryPoints: [join(here, "src", "extension.ts")],
bundle: true,
outfile: join(here, "bundle", "extension.js"),
format: "cjs",
platform: "node",
target: "node18",
external: ["vscode"],
minify: !watch,
sourcemap: watch,
};
// 2. Build Webview React App
mkdirSync(join(here, "media"), { recursive: true });
const webviewOptions = {
entryPoints: [join(here, "webview-ui", "src", "index.tsx")],
bundle: true,
outfile: join(here, "media", "webview.js"),
format: "iife",
target: "es2020",
minify: !watch,
sourcemap: watch,
define: { "process.env.NODE_ENV": watch ? '"development"' : '"production"' },
};
// Copy styles
try {
copyFileSync(join(here, "webview-ui", "src", "styles.css"), join(here, "media", "webview.css"));
} catch (e) {
// Ignore on first run before file exists
}
if (watch) {
const extCtx = await esbuild.context(extOptions);
const webCtx = await esbuild.context(webviewOptions);
await extCtx.watch();
await webCtx.watch();
console.log("watching extension and webview...");
} else {
await esbuild.build(extOptions);
await esbuild.build(webviewOptions);
console.log("bundled ->", extOptions.outfile, "and", webviewOptions.outfile);
}