-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathesbuild.js
More file actions
54 lines (48 loc) · 1.42 KB
/
esbuild.js
File metadata and controls
54 lines (48 loc) · 1.42 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
const esbuild = require('esbuild');
const fs = require('fs');
const path = require('path');
const watch = process.argv.includes('--watch');
const buildOptions = {
entryPoints: ['src/extension.ts'],
bundle: true,
outfile: 'dist/extension.js',
// External modules that cannot be bundled:
// - vscode: provided by VS Code at runtime
// - jiti: ESLint v9 flat config loader
// - eslint*, @typescript-eslint/*: ESLint and plugins - must be loaded at runtime
// to avoid initialization issues when bundled
external: [
'vscode',
'jiti',
'eslint',
'eslint-plugin-security',
'eslint-plugin-no-unsanitized',
'@typescript-eslint/parser',
],
format: 'cjs',
platform: 'node',
sourcemap: true,
minify: false,
target: 'node18'
};
async function build() {
try {
if (watch) {
const ctx = await esbuild.context(buildOptions);
await ctx.watch();
console.log('Watching for changes...');
} else {
await esbuild.build(buildOptions);
// Copy package.json to dist/ to fix runtime resolution issues
// Some bundled dependencies use __dirname to find package.json
const srcPkg = path.join(__dirname, 'package.json');
const distPkg = path.join(__dirname, 'dist', 'package.json');
fs.copyFileSync(srcPkg, distPkg);
console.log('Build complete');
}
} catch (error) {
console.error('Build failed:', error);
process.exit(1);
}
}
build();