Skip to content

Commit 9f4cda6

Browse files
jellymartinpitt
authored andcommitted
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/ Closes: #18267
1 parent 81bc367 commit 9f4cda6

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

build.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,13 @@ const qunitOptions = {
5050
const parser = (await import('argparse')).default.ArgumentParser();
5151
parser.add_argument('-r', '--rsync', { help: "rsync bundles to ssh target after build", metavar: "HOST" });
5252
parser.add_argument('-w', '--watch', { action: 'store_true', help: "Enable watch mode" });
53+
parser.add_argument('-m', '--metafile', { help: "Enable bund size information file", metavar: "FILE" });
5354
parser.add_argument('onlydir', { nargs: '?', help: "The pkg/<DIRECTORY> to build (eg. base1, shell, ...)", metavar: "DIRECTORY" });
5455
const args = parser.parse_args();
5556

57+
if (args.metafile)
58+
pkgOptions.metafile = true;
59+
5660
if (args.onlydir?.includes('/'))
5761
parser.error("Directory must not contain '/'");
5862

@@ -201,7 +205,9 @@ async function build() {
201205
});
202206

203207
try {
204-
await Promise.all([pkgContext.rebuild(), qunitContext.rebuild()]);
208+
const results = await Promise.all([pkgContext.rebuild(), qunitContext.rebuild()]);
209+
if (args.metafile)
210+
fs.writeFileSync(args.metafile, JSON.stringify(results[0].metafile));
205211
} catch (e) {
206212
if (!args.watch)
207213
process.exit(1);

0 commit comments

Comments
 (0)