-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathesbuild.js
61 lines (56 loc) · 1.64 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
const { build, context } = require('esbuild')
const baseConfig = (production) => {
return {
bundle: true,
minify: production === true,
sourcemap: production === false,
}
}
const extensionConfig = (production) => {
const cfg = baseConfig(production)
return {
...cfg,
platform: 'node',
mainFields: ['module', 'main'],
format: 'cjs',
entryPoints: ['./src/extension.ts'],
outfile: './out/extension.js',
external: ['vscode'],
}
}
const onEndPlugin = {
name: 'on-end',
setup(build) {
build.onEnd((result) => {
console.log(`build ended with ${result.errors.length} errors`)
if (result.errors.length > 0) {
result.errors.forEach((error) =>
console.error(
`> ${error.location.file}:${error.location.line}:${error.location.column}: error: ${error.text}`
)
)
}
})
},
}
;(async () => {
try {
const isProduction =
process.argv.includes('--production') || process.argv.includes('-p')
const extConfig = extensionConfig(isProduction)
if (process.argv.includes('--watch')) {
// Watch source code
const ctx = await context({
...extConfig,
plugins: [onEndPlugin],
})
await ctx.watch()
} else {
await build(extConfig)
console.log('extension build complete')
}
} catch (err) {
process.stderr.write(err.stderr)
process.exit(1)
}
})().catch(console.error)