Skip to content

Commit

Permalink
build.js: support outputting esbuild metadata file
Browse files Browse the repository at this point in the history
ESbuild supports outputting a metadata file which can be used to view
bundle size information using https://esbuild.github.io/analyze/

Closes: #18267
  • Loading branch information
jelly authored and martinpitt committed Jun 26, 2024
1 parent 81bc367 commit 9f4cda6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion build.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,13 @@ const qunitOptions = {
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" });
parser.add_argument('-m', '--metafile', { help: "Enable bund size information file", metavar: "FILE" });
parser.add_argument('onlydir', { nargs: '?', help: "The pkg/<DIRECTORY> to build (eg. base1, shell, ...)", metavar: "DIRECTORY" });
const args = parser.parse_args();

if (args.metafile)
pkgOptions.metafile = true;

if (args.onlydir?.includes('/'))
parser.error("Directory must not contain '/'");

Expand Down Expand Up @@ -201,7 +205,9 @@ async function build() {
});

try {
await Promise.all([pkgContext.rebuild(), qunitContext.rebuild()]);
const results = await Promise.all([pkgContext.rebuild(), qunitContext.rebuild()]);
if (args.metafile)
fs.writeFileSync(args.metafile, JSON.stringify(results[0].metafile));
} catch (e) {
if (!args.watch)
process.exit(1);
Expand Down

0 comments on commit 9f4cda6

Please sign in to comment.