Skip to content

feat(@angular/build): add keepDefaultConditions option - #34844

Open
damienwebdev wants to merge 7 commits into
angular:mainfrom
damienwebdev:feat/keep-default-conditions
Open

damienwebdev wants to merge 7 commits into
angular:mainfrom
damienwebdev:feat/keep-default-conditions

Conversation

@damienwebdev

Copy link
Copy Markdown

PR Checklist

Please check to confirm your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Setting conditions replaces the default module and development/production conditions. Adding one custom condition also drops the defaults, and keeping them means repeating module and development or production in every configuration, in sync with its optimization setting. It also means that if Angular changes its default conditions, then we have to track this change upstream, which is tedious.

Fixes: #34838

What is the new behavior?

A new keepDefaultConditions application option, false by default. When set, custom conditions are added to the defaults instead of replacing them, and the development/production condition still follows optimization.

The build, the dev server and the Vitest and Karma unit-test runners each read conditions separately. A refactor commit moves that into utils/resolve-conditions.ts, so the new option is handled in one place and applies to all of them.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

This is stacked on

which make the dev server and the unit-test runners use conditions. The last two commits are new here: the refactor and the feature.

Pass the build `conditions` to Vite's client and SSR `resolve.conditions`.
Without them, prebundled packages resolve with Vite's default conditions and
`ng serve` runs different code than `ng build`.

Fixes angular#34834
The Vitest runner sets its own `resolve.conditions`, so packages resolved by
Vite at test time ignored the build target's `conditions`. Use them in place
of the default `module` condition, as the build does.

Fixes angular#34835
…nner

The Karma runner of the unit-test builder copies a fixed set of options from
the build target, and `conditions` was not one of them. Pass it through to
the Karma test build.

Fixes angular#34836
The build, the dev server and the Vitest and Karma unit-test runners each read
the build `conditions` on their own. Read them in one place, along with the
default conditions of the build.
Setting `conditions` replaces the default `module` and
`development`/`production` conditions. With `keepDefaultConditions`, the
custom conditions are added to the defaults instead, and the
`development`/`production` condition still follows the `optimization` setting.
The option applies to the build, the dev server and the unit-test runners.

Closes angular#34838
@angular-robot angular-robot Bot added detected: feature PR contains a feature commit area: @angular/build labels Dec 4, 2026
@damienwebdev damienwebdev changed the title Feat/keep default conditions feat(@angular/build): add keepDefaultConditions option Dec 4, 2026

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

Copy link
Copy Markdown

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 new 'keepDefaultConditions' option to the application builder, allowing users to retain default package resolution conditions ('module' and 'development'/'production') when custom conditions are specified. The changes include a new utility for resolving these conditions, updates to the application, dev-server, and unit-test builders to support this configuration, and comprehensive test coverage for the new functionality. I have no feedback to provide as there were no review comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: @angular/build detected: feature PR contains a feature commit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow adding to the default conditions instead of replacing them

1 participant