Skip to content

Commit 91f5be7

Browse files
filipesilvaalexeagle
authored andcommitted
fix(@ngtools/webpack): don't load ngfactories for lazy routes with Ivy
Supersedes angular#13524
1 parent 5016843 commit 91f5be7

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

packages/ngtools/webpack/src/angular_compiler_plugin.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -500,10 +500,14 @@ 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 ||
504+
// When using Ivy and not using allowEmptyCodegenFiles, factories are not generated.
505+
(this._compilerOptions.enableIvy && !this._compilerOptions.allowEmptyCodegenFiles)
506+
) {
504507
modulePath = lazyRouteTSFile;
505508
moduleKey = `${lazyRouteModule}${moduleName ? '#' + moduleName : ''}`;
506509
} else {
510+
// NgFactories are only used with AOT on ngc (legacy) mode.
507511
modulePath = lazyRouteTSFile.replace(/(\.d)?\.tsx?$/, '');
508512
modulePath += '.ngfactory.js';
509513
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
@@ -129,7 +129,9 @@ allTests = allTests
129129
// NEEDS devkit change
130130
.filter(name => !name.endsWith('/existing-directory.ts'))
131131
// Disabled on rc.0 due to needed sync with devkit for changes.
132-
.filter(name => !name.endsWith('/service-worker.ts'));
132+
.filter(name => !name.endsWith('/service-worker.ts'))
133+
// Lazy load support is WIP https://github.com/angular/angular/pull/28685
134+
.filter(name => !name.endsWith('tests/experimental/ivy-lazy-load.ts'));
133135

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

0 commit comments

Comments
 (0)