-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.js
More file actions
57 lines (49 loc) · 1.52 KB
/
Copy pathbuild.js
File metadata and controls
57 lines (49 loc) · 1.52 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
const esbuild = require('esbuild');
const production = process.argv.includes('--production');
const watch = process.argv.includes('--watch');
const webOnly = process.argv.includes('--web-only');
const nodeBuildOptions = {
entryPoints: ['src/extension.ts'],
bundle: true,
outfile: 'out/extension.js',
platform: 'node',
format: 'cjs',
target: ['node16'],
minify: production,
sourcemap: production ? false : 'external',
external: ['vscode'],
logLevel: 'info'
};
const webBuildOptions = {
entryPoints: ['src/browserExtension.ts'],
bundle: true,
outfile: 'out/browserExtension.js',
platform: 'browser',
format: 'cjs',
target: ['es2022'],
minify: production,
sourcemap: production ? false : 'external',
external: ['vscode'],
logLevel: 'info'
};
async function main() {
console.log('[build] build started');
if (watch) {
const buildOptions = webOnly ? [webBuildOptions] : [nodeBuildOptions, webBuildOptions];
const contexts = await Promise.all(buildOptions.map(options => esbuild.context(options)));
await Promise.all(contexts.map(context => context.watch()));
console.log('[build] watching for changes...');
process.on('SIGINT', async () => {
await Promise.all(contexts.map(context => context.dispose()));
process.exit(0);
});
return;
}
const buildOptions = webOnly ? [webBuildOptions] : [nodeBuildOptions, webBuildOptions];
await Promise.all(buildOptions.map(options => esbuild.build(options)));
console.log('[build] build finished');
}
main().catch(error => {
console.error(error);
process.exit(1);
});