feat(@angular/build): Support splitting browser and server stats jsonfiles for easier consumption - #33870
feat(@angular/build): Support splitting browser and server stats jsonfiles for easier consumption#33870alan-agius4 wants to merge 2 commits into
Conversation
…files for easier consumption This feature supports splitting out the browser and server stats json files so it's easier to inspect the bundle in various analyzers and addresses angular#28185 angular#28671. Today, everything gets dumped into a single file and it's nearly impossible to use without hours of `fix -> remove unused browser/server chunks -> analyze` and starting the loop all over again. This feature implements the feature request I made in angular#28185, along with another developers request to see a stats json file for just the initial page bundle. I've tested this out in my own repository and it's already helped an incredible amount. This will be required to be in the next Major version as it will break any existing build pipeline that relies on a single stats.json file.
9f9ef20 to
9f8f54c
Compare
There was a problem hiding this comment.
Code Review
This pull request refactors the application builder to separate browser and server metafiles instead of merging them into a single metafile, enabling the generation of separate browser and server stats files. Feedback on these changes highlights two issues: first, removing the server bundle exclusion check in generateBudgetStats incorrectly includes server files in budget calculations, which should be resolved by filtering outputFiles beforehand; second, removing the BuildOutputFileType.Browser check in chunk-optimizer.ts allows server-side files to be added to chunk records, introducing unnecessary overhead.
…ndler context Track the target platform (`browser` or `server`) on individual bundler context results and introduce `BundleMergedContextResult` to maintain separate `browser` and `server` metafiles when merging. This simplifies downstream consumers: - Enables direct usage of `metafiles.browser` for browser-specific steps (budgets, i18n, chunk optimization, CommonJS checks, and post-bundle processing). - Allows `extractLicenses` and `logBuildStats` to process all platform metafiles directly without merging them into a single structure. - Removes redundant filtering of server bundles in budget calculations. - Streamlines the `statsJson` file emission for browser and server targets.
dgp1130
left a comment
There was a problem hiding this comment.
How do we feel about the breaking change of moving from stats.json -> browser-stats.json? That could break some existing workflows? Should this wait for a major or do we think it's ok to ship in a minor because the stats file typically isn't read for a normal build / deploy workflow?
See: #33209