build.js: support outputting esbuild metadata file
ESbuild supports outputting a metadata file which can be used to view bundle size information using https://esbuild.github.io/analyze/
This commit is contained in:
parent
d3758c3fef
commit
249d413262
1 changed files with 6 additions and 1 deletions
7
build.js
7
build.js
|
|
@ -19,6 +19,7 @@ const esbuild = (await import(useWasm ? 'esbuild-wasm' : 'esbuild')).default;
|
|||
const parser = (await import('argparse')).default.ArgumentParser();
|
||||
parser.add_argument('-r', '--rsync', { help: "rsync bundles to ssh target after build", metavar: "HOST" });
|
||||
parser.add_argument('-w', '--watch', { action: 'store_true', help: "Enable watch mode", default: process.env.ESBUILD_WATCH === "true" });
|
||||
parser.add_argument('-m', '--metafile', { help: "Enable bundle size information file", metavar: "FILE" });
|
||||
const args = parser.parse_args();
|
||||
|
||||
if (args.rsync)
|
||||
|
|
@ -82,6 +83,7 @@ const context = await esbuild.context({
|
|||
external: ['*.woff', '*.woff2', '*.jpg', '*.svg', '../../assets*'], // Allow external font files which live in ../../static/fonts
|
||||
legalComments: 'external', // Move all legal comments to a .LEGAL.txt file
|
||||
loader: { ".js": "jsx" },
|
||||
metafile: !!args.metafile,
|
||||
minify: production,
|
||||
nodePaths,
|
||||
outdir,
|
||||
|
|
@ -105,7 +107,10 @@ const context = await esbuild.context({
|
|||
});
|
||||
|
||||
try {
|
||||
await context.rebuild();
|
||||
const result = await context.rebuild();
|
||||
if (args.metafile) {
|
||||
fs.writeFileSync(args.metafile, JSON.stringify(result.metafile));
|
||||
}
|
||||
} catch (e) {
|
||||
if (!args.watch)
|
||||
process.exit(1);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue