Repository navigation
Expand file tree
/
Copy pathesbuild.js
More file actions
124 lines (113 loc) · 3.4 KB
/
Copy pathesbuild.js
File metadata and controls
124 lines (113 loc) · 3.4 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
const esbuild = require("esbuild")
const fs = require("fs")
const path = require("path")
const watch = process.argv.includes("--watch")
const production = process.argv.includes("--production")
const extensionConfig = {
entryPoints: ["src/extension.ts"],
bundle: true,
external: ["vscode"],
format: "cjs",
platform: "node",
// Prefer the ESM ("module") entry over UMD ("main") so esbuild can follow
// and bundle internal imports. Some packages (e.g. jsonc-parser) ship a UMD
// build whose require() calls inside the factory wrapper are not bundled,
// causing "Cannot find module './impl/format'" at runtime.
mainFields: ["module", "main"],
outdir: "dist",
sourcemap: !production,
minify: production,
treeShaking: true,
logLevel: "info",
}
const webviewConfig = {
entryPoints: [{ in: "src/chat/webview/main.ts", out: "chat/webview/main" }],
bundle: true,
format: "iife",
platform: "browser",
outdir: "dist",
sourcemap: false,
minify: production,
// @vscode-elements/elements is loaded via <script> tag in index.html
// (bundled.js) as a pre-built bundle that auto-registers all custom elements.
logLevel: "info",
}
const markdownWorkerConfig = {
entryPoints: [{ in: "src/chat/webview/markdownWorker.ts", out: "chat/webview/markdownWorker" }],
bundle: true,
format: "iife",
platform: "browser",
outdir: "dist",
sourcemap: false,
minify: production,
logLevel: "info",
}
const cssConfig = {
entryPoints: [{ in: "src/chat/webview/css/styles.css", out: "chat/webview/styles" }],
bundle: true,
outdir: "dist",
minify: production,
logLevel: "info",
loader: {
".woff": "file",
".woff2": "file",
".ttf": "file",
".eot": "file",
},
}
const mermaidVendorConfig = {
entryPoints: [{ in: "src/chat/webview/vendor/mermaidEntry.ts", out: "chat/webview/mermaid-vendor" }],
bundle: true,
format: "iife",
platform: "browser",
outdir: "dist",
minify: production,
logLevel: "info",
}
const katexVendorConfig = {
entryPoints: [{ in: "src/chat/webview/vendor/katexEntry.ts", out: "chat/webview/katex-vendor" }],
bundle: true,
format: "iife",
platform: "browser",
outdir: "dist",
minify: production,
logLevel: "info",
}
function copyWebviewAssets() {
const outDir = path.join("dist", "chat", "webview")
fs.mkdirSync(outDir, { recursive: true })
// index.html
fs.copyFileSync(
path.join("src", "chat", "webview", "index.html"),
path.join(outDir, "index.html")
)
// media
const mediaDir = path.join(outDir, "media")
fs.mkdirSync(mediaDir, { recursive: true })
fs.copyFileSync(
path.join("media", "opencode-wordmark-dark.svg"),
path.join(mediaDir, "opencode-wordmark-dark.svg")
)
}
if (watch) {
copyWebviewAssets()
Promise.all([
esbuild.context(extensionConfig).then(ctx => ctx.watch()),
esbuild.context(webviewConfig).then(ctx => ctx.watch()),
esbuild.context(markdownWorkerConfig).then(ctx => ctx.watch()),
esbuild.context(mermaidVendorConfig).then(ctx => ctx.watch()),
esbuild.context(katexVendorConfig).then(ctx => ctx.watch()),
esbuild.context(cssConfig).then(ctx => ctx.watch()),
])
} else {
Promise.all([
esbuild.build(extensionConfig),
esbuild.build(webviewConfig),
esbuild.build(markdownWorkerConfig),
esbuild.build(mermaidVendorConfig),
esbuild.build(katexVendorConfig),
esbuild.build(cssConfig),
])
.then(copyWebviewAssets)
.catch(() => process.exit(1))
}