From 82193807d51541e9ad44063674f0c1cf043361a7 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Tue, 16 Apr 2019 09:33:15 +0200 Subject: [PATCH] fix(@ngtools/webpack): replace bootstrap code under Ivy unless running in JIT mode The bootstrap code always needs to be replaced if not running in JIT mode as other wise the entire compiler will be pulled in because we will not replace the bootstrapping code to use `platform-browser` instead of `platform-browser-dynamic`. --- packages/ngtools/webpack/src/angular_compiler_plugin.ts | 6 +++--- .../ngtools/webpack/src/transformers/replace_bootstrap.ts | 4 ++-- .../webpack/src/transformers/replace_bootstrap_spec.ts | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) 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);