diff --git a/packages/angular_devkit/build_angular/src/builders/application/options.ts b/packages/angular_devkit/build_angular/src/builders/application/options.ts index 94d55e10b81a..914a30299766 100644 --- a/packages/angular_devkit/build_angular/src/builders/application/options.ts +++ b/packages/angular_devkit/build_angular/src/builders/application/options.ts @@ -284,7 +284,7 @@ export async function normalizeOptions( // Return all the normalized options return { - advancedOptimizations: !!aot, + advancedOptimizations: !!aot && optimizationOptions.scripts, allowedCommonJsDependencies, baseHref, cacheOptions, diff --git a/packages/angular_devkit/build_angular/src/builders/application/tests/behavior/angular-aot-metadata_spec.ts b/packages/angular_devkit/build_angular/src/builders/application/tests/behavior/angular-aot-metadata_spec.ts index fa136b105970..be84649bbed1 100644 --- a/packages/angular_devkit/build_angular/src/builders/application/tests/behavior/angular-aot-metadata_spec.ts +++ b/packages/angular_devkit/build_angular/src/builders/application/tests/behavior/angular-aot-metadata_spec.ts @@ -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(); @@ -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(); diff --git a/tests/legacy-cli/e2e/tests/build/prerender/error-with-sourcemaps.ts b/tests/legacy-cli/e2e/tests/build/prerender/error-with-sourcemaps.ts index 5661608d061b..993706407047 100644 --- a/tests/legacy-cli/e2e/tests/build/prerender/error-with-sourcemaps.ts +++ b/tests/legacy-cli/e2e/tests/build/prerender/error-with-sourcemaps.ts @@ -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+\)/, + ); }