Skip to content

Commit ed832ed

Browse files
clydinhansl
authored andcommitted
fix(@angular-devkit/build-angular): properly account for AOT in lazyModules option
1 parent 3a224e6 commit ed832ed

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed

packages/angular_devkit/build_angular/test/browser/lazy-module_spec_large.ts

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ describe('Browser Builder lazy modules', () => {
7676
beforeEach(done => host.initialize().subscribe(undefined, done.fail, done));
7777
afterEach(done => host.restore().subscribe(undefined, done.fail, done));
7878

79-
it('supports lazy bundle for lazy routes', (done) => {
79+
it('supports lazy bundle for lazy routes with JIT', (done) => {
8080
host.writeMultipleFiles(lazyModuleFiles);
8181
host.writeMultipleFiles(lazyModuleImport);
8282

@@ -88,6 +88,19 @@ describe('Browser Builder lazy modules', () => {
8888
).subscribe(undefined, done.fail, done);
8989
}, Timeout.Basic);
9090

91+
it('supports lazy bundle for lazy routes with AOT', (done) => {
92+
host.writeMultipleFiles(lazyModuleFiles);
93+
host.writeMultipleFiles(lazyModuleImport);
94+
95+
runTargetSpec(host, browserTargetSpec, { aot: true }).pipe(
96+
tap((buildEvent) => expect(buildEvent.success).toBe(true)),
97+
tap(() => {
98+
expect(host.scopedSync()
99+
.exists(join(outputPath, 'lazy-lazy-module-ngfactory.js'))).toBe(true);
100+
}),
101+
).subscribe(undefined, done.fail, done);
102+
}, Timeout.Basic);
103+
91104
it(`supports lazy bundle for import() calls`, (done) => {
92105
host.writeMultipleFiles({
93106
'src/lazy-module.ts': 'export const value = 42;',
@@ -180,7 +193,7 @@ describe('Browser Builder lazy modules', () => {
180193
).subscribe(undefined, done.fail, done);
181194
}, Timeout.Basic);
182195

183-
it(`supports extra lazy modules array`, (done) => {
196+
it(`supports extra lazy modules array in JIT`, (done) => {
184197
host.writeMultipleFiles(lazyModuleFiles);
185198
host.writeMultipleFiles({
186199
'src/app/app.component.ts': `
@@ -210,4 +223,40 @@ describe('Browser Builder lazy modules', () => {
210223
.toBe(true)),
211224
).subscribe(undefined, done.fail, done);
212225
}, Timeout.Basic);
226+
227+
it(`supports extra lazy modules array in AOT`, (done) => {
228+
host.writeMultipleFiles(lazyModuleFiles);
229+
host.writeMultipleFiles({
230+
'src/app/app.component.ts': `
231+
import { Component, SystemJsNgModuleLoader } from '@angular/core';
232+
233+
@Component({
234+
selector: 'app-root',
235+
templateUrl: './app.component.html',
236+
styleUrls: ['./app.component.css'],
237+
})
238+
export class AppComponent {
239+
title = 'app';
240+
constructor(loader: SystemJsNgModuleLoader) {
241+
// Module will be split at build time and loaded when requested below
242+
loader.load('src/app/lazy/lazy.module#LazyModule')
243+
.then((factory) => { /* Use factory here */ });
244+
}
245+
}`,
246+
});
247+
host.replaceInFile('src/tsconfig.app.json', `"module": "es2015"`, `"module": "esnext"`);
248+
249+
const overrides: Partial<BrowserBuilderSchema> = {
250+
lazyModules: ['src/app/lazy/lazy.module'],
251+
aot: true,
252+
optimization: true,
253+
};
254+
255+
runTargetSpec(host, browserTargetSpec, overrides).pipe(
256+
tap((buildEvent) => expect(buildEvent.success).toBe(true)),
257+
tap(() => expect(host.scopedSync()
258+
.exists(join(outputPath, 'src-app-lazy-lazy-module-ngfactory.js')))
259+
.toBe(true)),
260+
).subscribe(undefined, done.fail, done);
261+
}, Timeout.Basic);
213262
});

packages/ngtools/webpack/src/angular_compiler_plugin.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,8 @@ export class AngularCompilerPlugin {
492492
modulePath = lazyRouteTSFile;
493493
moduleKey = `${lazyRouteModule}${moduleName ? '#' + moduleName : ''}`;
494494
} else {
495-
modulePath = lazyRouteTSFile.replace(/(\.d)?\.ts$/, `.ngfactory.js`);
495+
modulePath = lazyRouteTSFile.replace(/(\.d)?\.ts$/, '');
496+
modulePath += '.ngfactory.js';
496497
const factoryModuleName = moduleName ? `#${moduleName}NgFactory` : '';
497498
moduleKey = `${lazyRouteModule}.ngfactory${factoryModuleName}`;
498499
}

0 commit comments

Comments
 (0)