Skip to content

Commit 4e10f9e

Browse files
committed
fix(@ngtools/webpack): don't load ngfactories for lazy routes with Ivy
Supersedes angular#13524
1 parent c4376d0 commit 4e10f9e

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

packages/ngtools/webpack/src/angular_compiler_plugin.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -500,10 +500,11 @@ export class AngularCompilerPlugin {
500500
const lazyRouteTSFile = discoveredLazyRoutes[lazyRouteKey].replace(/\\/g, '/');
501501
let modulePath: string, moduleKey: string;
502502

503-
if (this._JitMode) {
503+
if (this._JitMode || this._compilerOptions.enableIvy) {
504504
modulePath = lazyRouteTSFile;
505505
moduleKey = `${lazyRouteModule}${moduleName ? '#' + moduleName : ''}`;
506506
} else {
507+
// NgFactories are only used with AOT on ngc (legacy) mode.
507508
modulePath = lazyRouteTSFile.replace(/(\.d)?\.tsx?$/, '');
508509
modulePath += '.ngfactory.js';
509510
const factoryModuleName = moduleName ? `#${moduleName}NgFactory` : '';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
import { readdirSync } from 'fs';
9+
import { prependToFile, replaceInFile } from '../../utils/fs';
10+
import { ng } from '../../utils/process';
11+
import { createProject } from '../../utils/project';
12+
13+
export default async function() {
14+
await createProject('ivy-project', '--experimental-ivy');
15+
16+
await ng('generate', 'module', 'lazy', '--routing');
17+
await prependToFile('src/app/app.module.ts', `import { RouterModule } from '@angular/router';`);
18+
await replaceInFile('src/app/app.module.ts', 'imports: [', `imports: [
19+
RouterModule.forRoot([{ path: "lazy", loadChildren: "src/app/lazy/lazy.module#LazyModule" }]),
20+
`);
21+
await ng('build', '--named-chunks', '--aot');
22+
const distFiles = await readdirSync('dist/ivy-project');
23+
if (!distFiles.includes('lazy-lazy-module.js')
24+
|| distFiles.includes('lazy-lazy-module-ngfactory.js')) {
25+
throw new Error('The lazy module chunk should not be a ngfactory.');
26+
}
27+
}

tests/legacy-cli/e2e_runner.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,9 @@ allTests = allTests
130130
// NEEDS devkit change
131131
.filter(name => !name.endsWith('/existing-directory.ts'))
132132
// Disabled on rc.0 due to needed sync with devkit for changes.
133-
.filter(name => !name.endsWith('/service-worker.ts'));
133+
.filter(name => !name.endsWith('/service-worker.ts'))
134+
// Lazy load support is WIP https://github.com/angular/angular/pull/28685
135+
.filter(name => !name.endsWith('tests/experimental/ivy-lazy-load.ts'));
134136

135137
if (argv.ivy) {
136138
// These tests are disabled on the Ivy-only CI job because:
@@ -143,7 +145,7 @@ if (argv.ivy) {
143145
// Ivy doesn't support i18n externally at the moment.
144146
.filter(name => !name.includes('tests/i18n/'))
145147
.filter(name => !name.endsWith('tests/build/aot/aot-i18n.ts'))
146-
// Lazy load support is WIP https://github.com/angular/angular-cli/pull/13524
148+
// Lazy load support is WIP https://github.com/angular/angular/pull/28685
147149
.filter(name => !name.endsWith('tests/misc/lazy-module.ts'))
148150
// We don't have a library consumption story yet for Ivy.
149151
.filter(name => !name.endsWith('tests/generate/library/library-consumption.ts'));

0 commit comments

Comments
 (0)