@@ -2,9 +2,19 @@ import {readdirSync} from 'fs';
2
2
3
3
import { ng , silentNpm } from '../../utils/process' ;
4
4
import { appendToFile , writeFile , prependToFile , replaceInFile } from '../../utils/fs' ;
5
+ import { getGlobalVariable } from '../../utils/env' ;
5
6
6
7
7
8
export 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
+
8
18
let oldNumberOfFiles = 0 ;
9
19
return Promise . resolve ( )
10
20
. then ( ( ) => ng ( 'build' ) )
@@ -15,9 +25,9 @@ export default function() {
15
25
import { RouterModule } from '@angular/router';
16
26
` ) )
17
27
. 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 } }]),
21
31
` ) )
22
32
. then ( ( ) => ng ( 'build' , '--named-chunks' ) )
23
33
. then ( ( ) => readdirSync ( 'dist/test-project' ) )
@@ -28,11 +38,14 @@ export default function() {
28
38
}
29
39
oldNumberOfFiles = currentNumberOfDistFiles ;
30
40
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
+ }
36
49
}
37
50
} )
38
51
// verify System.import still works
0 commit comments