-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathesbuild.js
More file actions
65 lines (58 loc) · 1.83 KB
/
Copy pathesbuild.js
File metadata and controls
65 lines (58 loc) · 1.83 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
const esbuild = require("esbuild")
const fs = require("fs")
const path = require("path")
const production = process.argv.includes("--production")
const watch = process.argv.includes("--watch")
const outdir = path.join(__dirname, "dist")
/** @type {import('esbuild').BuildOptions} */
const extensionOptions = {
entryPoints: [path.join(__dirname, "src", "extension.ts")],
outfile: path.join(outdir, "extension.js"),
bundle: true,
format: "cjs",
platform: "node",
target: "node20",
external: ["vscode"],
sourcemap: !production,
minify: production,
logLevel: "info",
}
/** @type {import('esbuild').BuildOptions} */
const webviewOptions = {
entryPoints: [path.join(__dirname, "webview", "main.tsx")],
outfile: path.join(outdir, "webview.js"),
bundle: true,
format: "iife",
platform: "browser",
target: "chrome110",
sourcemap: !production,
minify: production,
jsx: "automatic",
jsxImportSource: "preact",
define: { "process.env.NODE_ENV": production ? '"production"' : '"development"' },
logLevel: "info",
}
function copyAssets() {
fs.mkdirSync(outdir, { recursive: true })
fs.copyFileSync(path.join(__dirname, "webview", "index.html"), path.join(outdir, "webview.html"))
fs.copyFileSync(path.join(__dirname, "webview", "styles.css"), path.join(outdir, "webview.css"))
fs.copyFileSync(path.join(__dirname, "media", "icon.svg"), path.join(outdir, "icon.svg"))
}
async function main() {
copyAssets()
if (watch) {
const ctx = await Promise.all([
esbuild.context(extensionOptions),
esbuild.context(webviewOptions),
])
await Promise.all(ctx.map((c) => c.watch()))
console.log("watching...")
} else {
await Promise.all([esbuild.build(extensionOptions), esbuild.build(webviewOptions)])
console.log("build complete")
}
}
main().catch((err) => {
console.error(err)
process.exit(1)
})