-
Notifications
You must be signed in to change notification settings - Fork 8
/
build.ts
79 lines (74 loc) · 2.36 KB
/
build.ts
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
#!/usr/bin/env tsx
import fs from 'node:fs/promises';
import path from 'node:path';
import type { BuildContext, BuildOptions } from 'esbuild';
import esbuild from 'esbuild';
const isWatchMode = process.argv.includes('--watch');
const options: BuildOptions = {
color: true,
logLevel: 'info',
entryPoints: ['src/extension.ts'],
bundle: true,
metafile: process.argv.includes('--metafile'),
outdir: './out/src',
external: [
'vscode',
'typescript', // vue-component-meta
],
format: 'cjs',
platform: 'node',
target: 'ESNext',
tsconfig: 'src/tsconfig.json',
sourcemap: process.argv.includes('--sourcemap'),
minify: process.argv.includes('--minify'),
plugins: [
{
name: 'umd2esm',
setup(build) {
build.onResolve({ filter: /^(vscode-.*|estree-walker|jsonc-parser)/ }, (args) => {
const pathUmdMay = require.resolve(args.path, {
paths: [args.resolveDir],
});
// Call twice the replace is to solve the problem of the path in Windows
const pathEsm = pathUmdMay
.replace('/umd/', '/esm/')
.replace('\\umd\\', '\\esm\\');
return { path: pathEsm };
});
},
},
{
name: 'meta',
setup(build) {
build.onEnd(async (result) => {
if (result.metafile && result.errors.length === 0) {
return fs.writeFile(
path.resolve(__dirname, './meta.json'),
JSON.stringify(result.metafile),
);
}
});
},
},
],
};
async function main() {
let ctx: BuildContext | undefined;
try {
if (isWatchMode) {
ctx = await esbuild.context(options);
await ctx.watch();
} else {
const result = await esbuild.build(options);
if (process.argv.includes('--analyze')) {
const chunksTree = await esbuild.analyzeMetafile(result.metafile!, { color: true });
console.log(chunksTree);
}
}
} catch (error) {
console.error(error);
ctx?.dispose();
process.exit(1);
}
}
main();