-
Notifications
You must be signed in to change notification settings - Fork 34
/
esbuild.js
98 lines (89 loc) · 2.93 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
95
96
97
98
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable no-undef */
const { build, context } = require('esbuild');
//@ts-check
/** @typedef {import('esbuild').BuildOptions} BuildOptions **/
const args = process.argv.slice(2);
/** @type BuildOptions */
const baseConfig = {
bundle: true,
minify: args.includes('--production'),
sourcemap: !args.includes('--production'),
};
// Config for extension source code (to be run in a Node-based context)
/** @type BuildOptions */
const extensionConfig = {
...baseConfig,
platform: 'node',
format: 'cjs',
entryPoints: ['./src/main.ts'],
outfile: './out/main.js',
external: ['vscode'],
};
// Config for extension source code (to be run in a Web-based context)
/** @type BuildOptions */
const extensionBrowserConfig = {
...baseConfig,
platform: 'browser',
format: 'cjs',
entryPoints: ['./src/main.browser.ts'],
outfile: './out/main.browser.js',
external: ['vscode'],
};
// Config for webview source code (to be run in a web-based context)
/** @type BuildOptions */
const webviewConfig = {
...baseConfig,
target: 'es2020',
format: 'esm',
tsconfig: 'tsconfig.webview.json',
entryPoints: ['./src/webview/check-result-view.tsx'],
outfile: './out/check-result-view.js',
loader: {
'.ttf': 'copy', // use the file loader to handle .ttf files
}
};
/** @type BuildOptions */
const webviewCurrentProofStepConfig = {
...baseConfig,
target: 'es2020',
format: 'esm',
tsconfig: 'tsconfig.webview.json',
entryPoints: ['./src/webview/current-proof-step/main.tsx'],
outfile: './out/current-proof-step.js',
loader: {
'.ttf': 'copy', // use the file loader to handle .ttf files
}
};
const watchPlugin = (name) => [{
name: 'watch-plugin',
setup(build) {
build.onStart(() => console.log(`[watch] build started - ${name}`));
build.onEnd(() => console.log(`[watch] build finished - ${name}`));
},
}];
// Build script
(async () => {
try {
if (args.includes('--watch')) {
// Build and watch extension
(await context({...extensionConfig, plugins: watchPlugin('extensionConfig')})).watch();
(await context({...extensionBrowserConfig, plugins: watchPlugin('extensionBrowserConfig')})).watch();
(await context({...webviewConfig, plugins: watchPlugin('webviewConfig')})).watch();
(await context({
...webviewCurrentProofStepConfig,
plugins: watchPlugin('webviewCurrentProofStepConfig')
})).watch();
} else {
// Build extension
await build(extensionConfig);
await build(extensionBrowserConfig);
await build(webviewConfig);
await build(webviewCurrentProofStepConfig);
console.log('build complete');
}
} catch (err) {
process.stderr.write(err.stderr);
process.exit(1);
}
})();