Skip to content

Commit b10d2a7

Browse files
committed
perf(@angular-devkit/build-angular): only enable advanced optimizations with script optimizations
When using the `application` or `browser-esbuild` builders, the internal advanced optimizations can only be applied when in AOT mode. However, they were previously only checking the AOT mode and not whether the project was configured to use script optimizations. The advanced optimizations are now conditional on both AOT mode and the `optimization.scripts` option. This can greatly improve the performance of builds in development since the Babel related processing can be skipped for all TypeScript application code.
1 parent e2f92ab commit b10d2a7

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

packages/angular_devkit/build_angular/src/builders/application/options.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ export async function normalizeOptions(
284284

285285
// Return all the normalized options
286286
return {
287-
advancedOptimizations: !!aot,
287+
advancedOptimizations: !!aot && optimizationOptions.scripts,
288288
allowedCommonJsDependencies,
289289
baseHref,
290290
cacheOptions,

packages/angular_devkit/build_angular/src/builders/application/tests/behavior/angular-aot-metadata_spec.ts

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
1414
it('should not emit any AOT class metadata functions', async () => {
1515
harness.useTarget('build', {
1616
...BASE_OPTIONS,
17+
optimization: true,
1718
});
1819

1920
const { result } = await harness.executeOnce();
@@ -25,6 +26,7 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
2526
it('should not emit any AOT NgModule scope metadata functions', async () => {
2627
harness.useTarget('build', {
2728
...BASE_OPTIONS,
29+
optimization: true,
2830
});
2931

3032
const { result } = await harness.executeOnce();

tests/legacy-cli/e2e/tests/build/prerender/error-with-sourcemaps.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,10 @@ export default async function () {
4444
const { message } = await expectToFail(() =>
4545
ng('build', '--configuration', 'development', '--prerender'),
4646
);
47-
match(message, /window is not defined[.\s\S]*constructor \(.*app\.component\.ts\:\d+:\d+\)/);
47+
match(
48+
message,
49+
// When babel is used it will add names to the sourcemap and `constructor` will be used in the stack trace.
50+
// This will currently only happen if AOT and script optimizations are set which enables advanced optimizations.
51+
/window is not defined[.\s\S]*(?:constructor|_AppComponent) \(.*app\.component\.ts\:\d+:\d+\)/,
52+
);
4853
}

0 commit comments

Comments
 (0)