Skip to content

Commit

Permalink
perf(@angular-devkit/build-angular): only enable advanced optimizatio…
Browse files Browse the repository at this point in the history
…ns 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.

(cherry picked from commit b10d2a7)
  • Loading branch information
clydin committed Dec 2, 2023
1 parent da5d394 commit e3820cb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ export async function normalizeOptions(

// Return all the normalized options
return {
advancedOptimizations: !!aot,
advancedOptimizations: !!aot && optimizationOptions.scripts,
allowedCommonJsDependencies,
baseHref,
cacheOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
it('should not emit any AOT class metadata functions', async () => {
harness.useTarget('build', {
...BASE_OPTIONS,
optimization: true,
});

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

const { result } = await harness.executeOnce();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,10 @@ export default async function () {
const { message } = await expectToFail(() =>
ng('build', '--configuration', 'development', '--prerender'),
);
match(message, /window is not defined[.\s\S]*constructor \(.*app\.component\.ts\:\d+:\d+\)/);
match(
message,
// When babel is used it will add names to the sourcemap and `constructor` will be used in the stack trace.
// This will currently only happen if AOT and script optimizations are set which enables advanced optimizations.
/window is not defined[.\s\S]*(?:constructor|_AppComponent) \(.*app\.component\.ts\:\d+:\d+\)/,
);
}

0 comments on commit e3820cb

Please sign in to comment.