Skip to content

Commit

Permalink
fix(@ngtools/webpack): replace bootstrap code under Ivy unless runnin…
Browse files Browse the repository at this point in the history
…g 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`.
  • Loading branch information
Alan Agius authored and alexeagle committed Apr 16, 2019
1 parent 2b23454 commit 8219380
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions packages/ngtools/webpack/src/angular_compiler_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ts.SourceFile> {

const standardTransform: StandardTransform = function (sourceFile: ts.SourceFile) {
Expand Down Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 8219380

Please sign in to comment.