diff --git a/packages/ngtools/webpack/src/angular_compiler_plugin.ts b/packages/ngtools/webpack/src/angular_compiler_plugin.ts index 636c6ceecb7d..af6c6826c049 100644 --- a/packages/ngtools/webpack/src/angular_compiler_plugin.ts +++ b/packages/ngtools/webpack/src/angular_compiler_plugin.ts @@ -948,13 +948,13 @@ export class AngularCompilerPlugin { this._normalizedLocale)); } - if (this._useFactories) { - // Replace bootstrap in browser AOT. + if (!this._JitMode) { + // Replace bootstrap in browser non JIT Mode. this._transformers.push(replaceBootstrap( isAppPath, getEntryModule, getTypeChecker, - !!this._compilerOptions.enableIvy, + this._useFactories, )); } } else if (this._platform === PLATFORM.Server) { diff --git a/packages/ngtools/webpack/src/transformers/replace_bootstrap.ts b/packages/ngtools/webpack/src/transformers/replace_bootstrap.ts index 064e8acedd67..37aeebcbbdb6 100644 --- a/packages/ngtools/webpack/src/transformers/replace_bootstrap.ts +++ b/packages/ngtools/webpack/src/transformers/replace_bootstrap.ts @@ -17,7 +17,7 @@ export function replaceBootstrap( shouldTransform: (fileName: string) => boolean, getEntryModule: () => { path: string, className: string } | null, getTypeChecker: () => ts.TypeChecker, - enableIvy?: boolean, + useFactories = true, ): ts.TransformerFactory { const standardTransform: StandardTransform = function (sourceFile: ts.SourceFile) { @@ -82,7 +82,7 @@ export function replaceBootstrap( let modulePath = `./${relativeEntryModulePath}`.replace(/\\/g, '/'); let bootstrapIdentifier = 'bootstrapModule'; - if (!enableIvy) { + if (useFactories) { className += 'NgFactory'; modulePath += '.ngfactory'; bootstrapIdentifier = 'bootstrapModuleFactory'; diff --git a/packages/ngtools/webpack/src/transformers/replace_bootstrap_spec.ts b/packages/ngtools/webpack/src/transformers/replace_bootstrap_spec.ts index 31358da6e4dd..0dc2742689d7 100644 --- a/packages/ngtools/webpack/src/transformers/replace_bootstrap_spec.ts +++ b/packages/ngtools/webpack/src/transformers/replace_bootstrap_spec.ts @@ -52,7 +52,7 @@ describe('@ngtools/webpack transformers', () => { expect(tags.oneLine`${result}`).toEqual(tags.oneLine`${output}`); }); - it('should replace bootstrap for Ivy without referencing ngFactory', () => { + it('should replace bootstrap without referencing ngFactory when useFactories is false', () => { const input = tags.stripIndent` import { enableProdMode } from '@angular/core'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; @@ -87,7 +87,7 @@ describe('@ngtools/webpack transformers', () => { () => true, () => ({ path: '/project/src/app/app.module', className: 'AppModule' }), () => program.getTypeChecker(), - true, + false, ); const result = transformTypescript(undefined, [transformer], program, compilerHost);