Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit fea7df6

Browse files
committedMar 26, 2025·
feat(@angular/build): support custom resolution conditions with applications
When using the application build system, a new `conditions` option is now available that allows adding custom package resolution conditions that can adjust the resolution for conditional exports and imports. By default the `module` and `production`/`development` conditions will be present with the later dependent on the `optimization` option. If any custom conditions value is present including an empty array, none of these defaults will be present and must be manually included if needed. The following special conditions will always be present if their respective requirements are satisfied: * es2015 (required by rxjs) * es2020 (APF backwards compatibility) * default * import * require * node * browser For additional information regarding conditional exports/imports: https://nodejs.org/api/packages.html#conditional-exports https://nodejs.org/api/packages.html#subpath-imports
1 parent 4a52a7b commit fea7df6

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed
 

‎packages/angular/build/src/builders/application/options.ts

+1
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ export async function normalizeOptions(
496496
security,
497497
templateUpdates: !!options.templateUpdates,
498498
incrementalResults: !!options.incrementalResults,
499+
customConditions: options.conditions,
499500
};
500501
}
501502

‎packages/angular/build/src/builders/application/schema.json

+7
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,13 @@
293293
"type": "string"
294294
}
295295
},
296+
"conditions": {
297+
"description": "Custom package resolution conditions used to resolve conditional exports/imports. Defaults to ['module', 'development'/'production']. The following special conditions are always present if the requirements are satisfied: 'default', 'import', 'require', 'browser', 'node'.",
298+
"type": "array",
299+
"items": {
300+
"type": "string"
301+
}
302+
},
296303
"fileReplacements": {
297304
"description": "Replace compilation source files with other compilation source files in the build.",
298305
"type": "array",

‎packages/angular/build/src/tools/esbuild/application-code-bundle.ts

+18-6
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ function getEsBuildCommonOptions(options: NormalizedApplicationBuildOptions): Bu
546546
loaderExtensions,
547547
jsonLogs,
548548
i18nOptions,
549+
customConditions,
549550
} = options;
550551

551552
// Ensure unique hashes for i18n translation changes when using post-process inlining.
@@ -563,18 +564,29 @@ function getEsBuildCommonOptions(options: NormalizedApplicationBuildOptions): Bu
563564
footer = { js: `/**i18n:${createHash('sha256').update(i18nHash).digest('hex')}*/` };
564565
}
565566

567+
// Core conditions that are always included
568+
const conditions = [
569+
// Required to support rxjs 7.x which will use es5 code if this condition is not present
570+
'es2015',
571+
'es2020',
572+
];
573+
574+
// Append custom conditions if present
575+
if (customConditions) {
576+
conditions.push(...customConditions);
577+
} else {
578+
// Include default conditions
579+
conditions.push('module');
580+
conditions.push(optimizationOptions.scripts ? 'production' : 'development');
581+
}
582+
566583
return {
567584
absWorkingDir: workspaceRoot,
568585
format: 'esm',
569586
bundle: true,
570587
packages: 'bundle',
571588
assetNames: outputNames.media,
572-
conditions: [
573-
'es2020',
574-
'es2015',
575-
'module',
576-
optimizationOptions.scripts ? 'production' : 'development',
577-
],
589+
conditions,
578590
resolveExtensions: ['.ts', '.tsx', '.mjs', '.js', '.cjs'],
579591
metafile: true,
580592
legalComments: options.extractLicenses ? 'none' : 'eof',

0 commit comments

Comments
 (0)
Please sign in to comment.