@@ -40,7 +40,7 @@ export class AotPlugin implements Tapable {
40
40
private _rootFilePath : string [ ] ;
41
41
private _compilerHost : WebpackCompilerHost ;
42
42
private _resourceLoader : WebpackResourceLoader ;
43
- private _lazyRoutes : { [ route : string ] : string } = Object . create ( null ) ;
43
+ private _lazyRoutes : LazyRouteMap = Object . create ( null ) ;
44
44
private _tsConfigPath : string ;
45
45
private _entryModule : string ;
46
46
@@ -201,19 +201,22 @@ export class AotPlugin implements Tapable {
201
201
private _findLazyRoutesInAst ( ) : LazyRouteMap {
202
202
const result : LazyRouteMap = Object . create ( null ) ;
203
203
const changedFilePaths = this . _compilerHost . getChangedFilePaths ( ) ;
204
- for ( const filePath in changedFilePaths ) {
204
+ for ( const filePath of changedFilePaths ) {
205
205
const fileLazyRoutes = findLazyRoutes ( filePath , this . _program , this . _compilerHost ) ;
206
206
for ( const routeKey of Object . keys ( fileLazyRoutes ) ) {
207
207
const route = fileLazyRoutes [ routeKey ] ;
208
208
if ( routeKey in this . _lazyRoutes ) {
209
209
if ( route === null ) {
210
210
this . _lazyRoutes [ routeKey ] = null ;
211
211
} else if ( this . _lazyRoutes [ routeKey ] !== route ) {
212
- throw new Error ( `Duplicated path in loadChildren detected: "${ routeKey } " is used in 2 `
213
- + `loadChildren, but they point to different modules `
214
- + `("${ this . _lazyRoutes [ routeKey ] } " and "${ route } "). Webpack cannot `
215
- + `distinguish on context and would fail to load the proper one.` ) ;
212
+ this . _compilation . warnings . push (
213
+ new Error ( `Duplicated path in loadChildren detected during a rebuild. `
214
+ + `We will take the latest version detected and override it to save rebuild time. `
215
+ + `You should perform a full build to validate that your routes don't overlap.` )
216
+ ) ;
216
217
}
218
+ } else {
219
+ result [ routeKey ] = route ;
217
220
}
218
221
}
219
222
}
@@ -346,13 +349,12 @@ export class AotPlugin implements Tapable {
346
349
. then ( ( ) => {
347
350
// Populate the file system cache with the virtual module.
348
351
this . _compilerHost . populateWebpackResolver ( this . _compiler . resolvers . normal ) ;
349
- this . _compilerHost . resetChangedFileTracker ( ) ;
350
352
} )
351
353
. then ( ( ) => {
352
354
// We need to run the `listLazyRoutes` the first time because it also navigates libraries
353
355
// and other things that we might miss using the findLazyRoutesInAst.
354
- let discoveredLazyRoutes : LazyRouteMap = this . firstRun
355
- ? __NGTOOLS_PRIVATE_API_2 . listLazyRoutes ( {
356
+ let discoveredLazyRoutes : LazyRouteMap = this . firstRun ?
357
+ __NGTOOLS_PRIVATE_API_2 . listLazyRoutes ( {
356
358
program : this . _program ,
357
359
host : this . _compilerHost ,
358
360
angularCompilerOptions : this . _angularCompilerOptions ,
@@ -365,6 +367,10 @@ export class AotPlugin implements Tapable {
365
367
. forEach ( k => {
366
368
const lazyRoute = discoveredLazyRoutes [ k ] ;
367
369
k = k . split ( '#' ) [ 0 ] ;
370
+ if ( lazyRoute === null ) {
371
+ return ;
372
+ }
373
+
368
374
if ( this . skipCodeGeneration ) {
369
375
this . _lazyRoutes [ k ] = lazyRoute ;
370
376
} else {
@@ -374,10 +380,12 @@ export class AotPlugin implements Tapable {
374
380
} ) ;
375
381
} )
376
382
. then ( ( ) => {
383
+ this . _compilerHost . resetChangedFileTracker ( ) ;
384
+
385
+ // Only turn this off for the first successful run.
377
386
this . _firstRun = false ;
378
387
cb ( ) ;
379
388
} , ( err : any ) => {
380
- this . _firstRun = false ;
381
389
compilation . errors . push ( err ) ;
382
390
cb ( ) ;
383
391
} ) ;
0 commit comments