-
Notifications
You must be signed in to change notification settings - Fork 0
/
esbuild.config.js
47 lines (43 loc) · 1.2 KB
/
esbuild.config.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
const esbuild = require('esbuild');
const isProduction = process.argv.includes('production');
const isWatch = process.argv.includes('watch');
/** @type {import('esbuild').BuildOptions} */
const buildOptions = {
entryPoints: ['./src/extension.ts'],
bundle: true,
outfile: './out/extension.js',
platform: 'node',
target: 'node14',
format: 'cjs',
external: ['vscode'], // Required for VSCode extensions
minify: isProduction, // Minify in production mode
sourcemap: !isProduction,
tsconfig: './tsconfig.json',
logLevel: 'info',
// Production optimizations
...(isProduction && {
drop: ['console', 'debugger'],
treeShaking: true,
legalComments: 'none',
mangleProps: /^_/,
minifyIdentifiers: true,
minifySyntax: true,
minifyWhitespace: true
})
};
async function build() {
try {
if (isWatch) {
const ctx = await esbuild.context(buildOptions);
await ctx.watch();
console.log('👀 Watching for changes...');
} else {
await esbuild.build(buildOptions);
console.log(`✨ Build complete ${isProduction ? '(production)' : '(development)'}`);
}
} catch (err) {
console.error('❌ Build failed:', err);
process.exit(1);
}
}
build();