-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathesbuild.js
More file actions
49 lines (43 loc) · 1.23 KB
/
Copy pathesbuild.js
File metadata and controls
49 lines (43 loc) · 1.23 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
const esbuild = require("esbuild");
const fs = require("fs");
const path = require("path");
const production = process.argv.includes("--production");
const watch = process.argv.includes("--watch");
/** Copy marked (UMD build) into dist so the webview can load it locally
* instead of from a CDN (which VS Code's default webview CSP blocks). */
function copyMarkedToDist() {
const src = require.resolve("marked/marked.min.js");
const destDir = path.join(__dirname, "dist", "webview");
fs.mkdirSync(destDir, { recursive: true });
fs.copyFileSync(src, path.join(destDir, "marked.min.js"));
}
async function buildExtension() {
const ctx = await esbuild.context({
entryPoints: ["src/extension.ts"],
bundle: true,
format: "cjs",
minify: production,
sourcemap: !production,
sourcesContent: false,
platform: "node",
target: "node16",
outfile: "dist/extension.js",
external: ["vscode"],
logLevel: "silent",
});
if (watch) {
await ctx.watch();
console.log("[watch] build started, watching for changes...");
} else {
await ctx.rebuild();
await ctx.dispose();
}
}
async function main() {
copyMarkedToDist();
await buildExtension();
}
main().catch((e) => {
console.error("[esbuild] build failed:", e);
process.exit(1);
});