@@ -2,9 +2,19 @@ import {readdirSync} from 'fs';
22
33import { ng , silentNpm } from '../../utils/process' ;
44import { appendToFile , writeFile , prependToFile , replaceInFile } from '../../utils/fs' ;
5+ import { getGlobalVariable } from '../../utils/env' ;
56
67
78export default function ( ) {
9+ const argv = getGlobalVariable ( 'argv' ) ;
10+ const ivyProject = argv [ 'ivy' ] ;
11+ const lazyImport = ivyProject ? `() => import('src/app/lazy/lazy.module').then(m => m.LazyModule)`
12+ : `'src/app/lazy/lazy.module#LazyModule'` ;
13+ const lazyImport1 = ivyProject ? `() => import('./lazy/lazy.module').then(m => m.LazyModule)`
14+ : `'./lazy/lazy.module#LazyModule'` ;
15+ const lazyImport2 = ivyProject ? `() => import('./too/lazy/lazy.module').then(m => m.LazyModule)`
16+ : `'./too/lazy/lazy.module#LazyModule'` ;
17+
818 let oldNumberOfFiles = 0 ;
919 return Promise . resolve ( )
1020 . then ( ( ) => ng ( 'build' ) )
@@ -15,9 +25,9 @@ export default function() {
1525 import { RouterModule } from '@angular/router';
1626 ` ) )
1727 . then ( ( ) => replaceInFile ( 'src/app/app.module.ts' , 'imports: [' , `imports: [
18- RouterModule.forRoot([{ path: "lazy", loadChildren: "src/app/lazy/lazy.module#LazyModule" }]),
19- RouterModule.forRoot([{ path: "lazy1", loadChildren: "./lazy/lazy.module#LazyModule" }]),
20- RouterModule.forRoot([{ path: "lazy2", loadChildren: "./too/lazy/lazy.module#LazyModule" }]),
28+ RouterModule.forRoot([{ path: "lazy", loadChildren: ${ lazyImport } }]),
29+ RouterModule.forRoot([{ path: "lazy1", loadChildren: ${ lazyImport1 } }]),
30+ RouterModule.forRoot([{ path: "lazy2", loadChildren: ${ lazyImport2 } }]),
2131 ` ) )
2232 . then ( ( ) => ng ( 'build' , '--named-chunks' ) )
2333 . then ( ( ) => readdirSync ( 'dist/test-project' ) )
@@ -28,11 +38,14 @@ export default function() {
2838 }
2939 oldNumberOfFiles = currentNumberOfDistFiles ;
3040
31- if ( ! distFiles . includes ( 'lazy-lazy-module.js' ) ) {
32- throw new Error ( 'The lazy module chunk did not have a name.' ) ;
33- }
34- if ( ! distFiles . includes ( 'too-lazy-lazy-module.js' ) ) {
35- throw new Error ( 'The lazy module chunk did not use a unique name.' ) ;
41+ // Named lazy route chunks are not available with Ivy.
42+ if ( ! ivyProject ) {
43+ if ( ! distFiles . includes ( 'lazy-lazy-module.js' ) ) {
44+ throw new Error ( 'The lazy module chunk did not have a name.' ) ;
45+ }
46+ if ( ! distFiles . includes ( 'too-lazy-lazy-module.js' ) ) {
47+ throw new Error ( 'The lazy module chunk did not use a unique name.' ) ;
48+ }
3649 }
3750 } )
3851 // verify System.import still works
0 commit comments