Skip to content

build: Make pnpm build-profile emit usable rspack stats - #124296

Merged
ryan953 merged 4 commits into
masterfrom
ryan953/rspack-stats
Sep 15, 2026
Merged

ryan953 merged 4 commits into
masterfrom
ryan953/rspack-stats

Conversation

@ryan953

@ryan953 ryan953 commented Sep 14, 2026

Copy link
Copy Markdown
Member

pnpm build-profile did not produce a file anyone could analyze. The old script passed --profile, which rspack no longer accepts, and fixing the flag alone was not enough. rspack --json writes whatever the configured stats options describe, and the CLI gives you no flag to override them. rspack.config.ts set no stats, so the CLI filled in its own default — the errors-warnings preset, which it applies whenever stats is unspecified, independently of mode — and the JSON came out with no assets, chunks, or entrypoints in it at all. Setting stats without trimming it lands at the other extreme: module records carry their source text, which grew the output past 300MB.

RSPACK_STATS=1 now gates a trimmed stats object applied to both the app and service-worker configs. The env gate keeps normal builds and the dev server untouched, which seemed better than adding a second root-level config file just for profiling. The script also pins NODE_ENV=production and --mode production so the profile matches build-production, and it writes through --json=stats.rspack.json instead of a shell redirect so CLI logging cannot end up inside the JSON.

The gated block keeps the bundle shape: assets, chunks, chunk groups, entrypoints, and chunk parent/child/sibling relations, so the graph stays walkable. On the app compiler that is 5303 assets, 1684 chunks, the app, gsAdmin and sentry entrypoints, and 9 named chunk groups. Module records are included with source: false, so module identity and nesting survive while the source text that pushed the file past 300MB stays out.

The output file is gitignored.

https://claude.ai/code/session_01Jp2jDjcwahdDYBBSmWFVXc

@ryan953
ryan953 requested a review from a team as a code owner September 14, 2026 16:50
@github-actions github-actions Bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Sep 14, 2026
@ryan953
ryan953 marked this pull request as draft September 14, 2026 16:53
`rspack --json` takes its stats options from the config, and the CLI has no
flag to override them. Under `--mode production` the default preset drops to
errors and warnings, so the file carried no assets, chunks, or entrypoints.
Without that flag the default preset dumps every module with its source and
the file grows past 300MB, which no analyzer will open.

RSPACK_STATS gates a trimmed stats object on both configs, so build-profile
now writes a ~3MB file holding the asset, chunk, and entrypoint data.

Claude-Session: https://claude.ai/code/session_01Jp2jDjcwahdDYBBSmWFVXc
@ryan953 ryan953 changed the title build: Fix pnpm build-profile and ignore the output file build: Make pnpm build-profile emit usable rspack stats Sep 14, 2026
@ryan953
ryan953 marked this pull request as ready for review September 14, 2026 22:03

@scttcper scttcper left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review by Astra. The env gate and direct JSON file output look reasonable. Two suggestions below: retain module detail if this is intended for bundle analyzers, and clarify the CLI defaults in the comment and PR description.

Comment thread rspack.config.ts
Comment thread rspack.config.ts Outdated
ryan953 and others added 2 commits September 15, 2026 11:18
Co-authored-by: Scott Cooper <scttcper@gmail.com>
Co-authored-by: Scott Cooper <scttcper@gmail.com>
@ryan953
ryan953 enabled auto-merge (squash) September 15, 2026 18:36
@ryan953
ryan953 merged commit 698b3be into master Sep 15, 2026
79 of 80 checks passed
@ryan953
ryan953 deleted the ryan953/rspack-stats branch September 15, 2026 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants