Skip to content

Commit 8783d02

Browse files
committed
fix(@ngtools/webpack): don't load ngfactories with Ivy
Supersedes angular#13524 Blocked on angular#13597 Blocked on angular/angular#28685
1 parent 6fc6e84 commit 8783d02

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
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/test-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+
}

0 commit comments

Comments
 (0)