Skip to content

feat(@angular/build): enable chunk optimization by default with heuristics#32971

Merged
alan-agius4 merged 2 commits intoangular:mainfrom
clydin:application/chunk-opt-stable
Apr 10, 2026
Merged

feat(@angular/build): enable chunk optimization by default with heuristics#32971
alan-agius4 merged 2 commits intoangular:mainfrom
clydin:application/chunk-opt-stable

Conversation

@clydin
Copy link
Copy Markdown
Member

@clydin clydin commented Apr 9, 2026

Enable the advanced chunk optimization pass by default for applications with multiple lazy chunks to improve loading performance. A heuristic is introduced that automatically triggers this optimization when the build generates 3 or more lazy chunks. Developers can customize this behavior or disable it entirely using the NG_BUILD_OPTIMIZE_CHUNKS environment variable. Setting it to a number adjusts the threshold of lazy chunks required to trigger optimization, while setting it to false disables the feature if issues arise in specific projects.

@clydin clydin added the target: major This PR is targeted for the next major release label Apr 9, 2026
@angular-robot angular-robot bot added detected: feature PR contains a feature commit area: @angular/build labels Apr 9, 2026
@clydin clydin force-pushed the application/chunk-opt-stable branch 4 times, most recently from 2ade868 to ae4b8c3 Compare April 9, 2026 13:50
This commit transitions the chunk optimization logic in the application builder from the experimental Rolldown bundler to the stable Rollup bundler. Rollup is now used by default, while support for the NG_BUILD_CHUNKS_ROLLDOWN environment variable has been added to allow opting back into Rolldown for testing and debugging. To make Rolldown truly optional for end users, it has been moved from dependencies to devDependencies, and is now loaded via dynamic import only when requested.
@clydin clydin force-pushed the application/chunk-opt-stable branch 7 times, most recently from ab860cd to 189b33d Compare April 9, 2026 19:19
@clydin clydin added the action: review The PR is still awaiting reviews from at least one requested reviewer label Apr 9, 2026
@clydin clydin marked this pull request as ready for review April 9, 2026 19:37
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a heuristic-based chunk optimization pass that runs after the initial esbuild bundle. It replaces the previous unconditional optimization with a threshold-based approach (defaulting to 3 lazy chunks) and adds support for using Rollup or Rolldown as the optimization engine. Several improvements were made to the chunk optimizer to handle entry point identification and environment configuration. I have identified a potential issue regarding the removal of the entry point check, a concern about the compatibility of manifest generation with optimized chunks, and a suggestion to improve the robustness of the environment variable parsing.

@clydin clydin force-pushed the application/chunk-opt-stable branch from 189b33d to b1e4260 Compare April 9, 2026 21:25
@clydin clydin requested a review from alan-agius4 April 9, 2026 21:36
…stics

Enable the advanced chunk optimization pass by default for applications with multiple lazy chunks to improve loading performance. A heuristic is introduced that automatically triggers this optimization when the build generates 3 or more lazy chunks. Developers can customize this behavior or disable it entirely using the NG_BUILD_OPTIMIZE_CHUNKS environment variable. Setting it to a number adjusts the threshold of lazy chunks required to trigger optimization, while setting it to false disables the feature if issues arise in specific projects.
@clydin clydin force-pushed the application/chunk-opt-stable branch from b1e4260 to 2b8e08d Compare April 9, 2026 21:48
@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Apr 10, 2026
@alan-agius4 alan-agius4 merged commit cd2ad3c into angular:main Apr 10, 2026
36 checks passed
@alan-agius4
Copy link
Copy Markdown
Collaborator

This PR was merged into the repository. The changes were merged into the following branches:

@clydin clydin deleted the application/chunk-opt-stable branch April 10, 2026 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: @angular/build detected: feature PR contains a feature commit target: major This PR is targeted for the next major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants