-
Notifications
You must be signed in to change notification settings - Fork 3
/
esbuild.js
95 lines (84 loc) · 2.19 KB
/
esbuild.js
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 production = process.argv.includes('--production');
const watch = process.argv.includes('--watch');
/**
* @type {import('esbuild').Plugin}
*/
const esbuildProblemMatcherPlugin = {
name: 'problem-matcher',
setup(build) {
build.onStart(() => {
console.log('[watch] build started');
});
build.onEnd(result => {
console.log(`Build ${build.initialOptions.outfile} finished`);
if (result.errors.length) {
result.errors.forEach(error => {
console.error(error);
});
}
});
}
};
const commonConfig = {
bundle: true,
minify: production,
sourcemap: !production,
logLevel: 'info',
};
const extensionConfig = {
...commonConfig,
entryPoints: ['src/extension_core/extension.ts'],
format: 'cjs',
platform: 'node',
outfile: 'dist/extension.js',
external: ['vscode'], // Only external we actually need
plugins: [esbuildProblemMatcherPlugin],
};
const workerConfig = {
...commonConfig,
entryPoints: ['src/extension_core/worker.ts'],
format: 'iife', // Self-executing function for worker scope
platform: 'node',
outfile: 'dist/worker.js',
plugins: [esbuildProblemMatcherPlugin],
target: 'es2020', // Modern browsers support WASM
};
const webviewConfig = {
...commonConfig,
entryPoints: ['src/webview/vaporview.ts'],
format: 'iife',
platform: 'browser',
outfile: 'dist/webview.js',
plugins: [esbuildProblemMatcherPlugin],
target: ['es2020'],
treeShaking: production,
metafile: true, // To analyze bundle
};
async function main() {
try {
if (watch) {
const extensionCtx = await esbuild.context(extensionConfig);
const webviewCtx = await esbuild.context(webviewConfig);
const workerCtx = await esbuild.context(workerConfig);
await Promise.all([
extensionCtx.watch(),
webviewCtx.watch(),
workerCtx.watch()
]);
} else {
await Promise.all([
esbuild.build(extensionConfig),
esbuild.build(webviewConfig),
esbuild.build(workerConfig)
]);
}
} catch (err) {
console.error('Build failed:', err);
process.exit(1);
}
}
main().catch(e => {
console.error(e);
process.exit(1);
});