Repository navigation
Expand file tree
/
Copy pathesbuild.js
More file actions
94 lines (84 loc) · 2.41 KB
/
Copy pathesbuild.js
File metadata and controls
94 lines (84 loc) · 2.41 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
const esbuild = require('esbuild');
const fs = require('fs');
const path = require('path');
const production = process.argv.includes('--production');
const watch = process.argv.includes('--watch');
function copyCodicons() {
const src = path.join('node_modules', '@vscode', 'codicons', 'dist');
const dst = path.join('out', 'codicons');
fs.mkdirSync(dst, { recursive: true });
for (const f of ['codicon.css', 'codicon.ttf']) {
fs.copyFileSync(path.join(src, f), path.join(dst, f));
}
}
const problemMatcher = {
name: 'problem-matcher',
setup(build) {
build.onStart(() => console.log('[esbuild] build started'));
build.onEnd((result) => {
for (const { text, location } of result.errors) {
console.error(`[esbuild] ${text}`);
if (location) {
console.error(` ${location.file}:${location.line}:${location.column}`);
}
}
console.log(`[esbuild] build finished (${result.errors.length} errors)`);
});
},
};
async function main() {
copyCodicons();
// Options shared by every bundle; per-context keys override below.
const shared = {
bundle: true,
sourcemap: !production,
minify: production,
logLevel: 'silent',
alias: { '@': path.resolve(__dirname, 'src') },
plugins: [problemMatcher],
};
const extensionCtx = await esbuild.context({
...shared,
entryPoints: ['src/extension.ts'],
format: 'cjs',
platform: 'node',
target: 'node22',
outfile: 'out/extension.js',
external: ['vscode', 'node-rsa'],
});
const hostTestCtx = await esbuild.context({
...shared,
entryPoints: ['src/host/index.ts'],
format: 'cjs',
platform: 'node',
target: 'node22',
outfile: 'out/hostTests.js',
external: ['vscode', 'mocha'],
});
// One bundle per webview; renderHtml loads out/<view>.js.
const webviewCtx = await esbuild.context({
...shared,
entryPoints: [
'src/ui/webviews/sessions.tsx',
'src/ui/webviews/hosts.tsx',
'src/ui/webviews/stats.tsx',
'src/ui/webviews/summary.tsx',
],
format: 'iife',
platform: 'browser',
target: 'es2022',
outdir: 'out',
jsx: 'automatic',
jsxImportSource: 'preact',
});
if (watch) {
await Promise.all([extensionCtx.watch(), webviewCtx.watch(), hostTestCtx.watch()]);
} else {
await Promise.all([extensionCtx.rebuild(), webviewCtx.rebuild(), hostTestCtx.rebuild()]);
await Promise.all([extensionCtx.dispose(), webviewCtx.dispose(), hostTestCtx.dispose()]);
}
}
main().catch((e) => {
console.error(e);
process.exit(1);
});