Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 68 additions & 63 deletions build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,72 +8,77 @@ 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),
);
}
});
},
},
],
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);
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);
}
const chunksTree = await esbuild.analyzeMetafile(result.metafile!, {
color: true,
});
console.log(chunksTree);
}
}
} catch (error) {
console.error(error);
ctx?.dispose();
process.exit(1);
}
}

main();
main();
Loading
Loading