From e5908e2c13c2240433493b062f94ab748b2d4e00 Mon Sep 17 00:00:00 2001 From: Jelle van der Waa Date: Tue, 11 Jun 2024 22:36:38 +0200 Subject: [PATCH] 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/ --- build.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/build.js b/build.js index aa400afc0..ddd94f249 100755 --- a/build.js +++ b/build.js @@ -27,6 +27,7 @@ const packageJson = JSON.parse(fs.readFileSync('package.json')); 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) @@ -84,6 +85,7 @@ const context = await esbuild.context({ ".js": "jsx", ".py": "text", }, + metafile: !!args.metafile, minify: production, nodePaths, outdir, @@ -118,7 +120,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);