diff --git a/build.js b/build.js index 4210743f..d0b5df01 100755 --- a/build.js +++ b/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);