@@ -89,6 +89,7 @@ export interface AngularCompilerPluginOptions {
89
89
tsConfigPath : string ;
90
90
basePath ?: string ;
91
91
entryModule ?: string ;
92
+ entryModules ?: string [ ] ;
92
93
mainPath ?: string ;
93
94
skipCodeGeneration ?: boolean ;
94
95
hostReplacementPaths ?: { [ path : string ] : string } | ( ( path : string ) => string ) ;
@@ -138,6 +139,7 @@ export class AngularCompilerPlugin {
138
139
private _lazyRoutes : LazyRouteMap = { } ;
139
140
private _tsConfigPath : string ;
140
141
private _entryModule : string | null ;
142
+ private _entryModules : string [ ] | null ;
141
143
private _mainPath : string | undefined ;
142
144
private _basePath : string ;
143
145
private _transformers : ts . TransformerFactory < ts . SourceFile > [ ] = [ ] ;
@@ -170,15 +172,18 @@ export class AngularCompilerPlugin {
170
172
171
173
get options ( ) { return this . _options ; }
172
174
get done ( ) { return this . _donePromise ; }
173
- get entryModule ( ) {
174
- if ( ! this . _entryModule ) {
175
+ get entryModules ( ) {
176
+ if ( ! this . _entryModules ) {
175
177
return null ;
176
178
}
177
- const splitted = this . _entryModule . split ( / ( # [ a - z A - Z _ ] ( [ \w ] + ) ) $ / ) ;
178
- const path = splitted [ 0 ] ;
179
- const className = ! ! splitted [ 1 ] ? splitted [ 1 ] . substring ( 1 ) : 'default' ;
180
179
181
- return { path, className } ;
180
+ return this . _entryModules . map ( ( entryModule ) => {
181
+ const splitted = entryModule . split ( / ( # [ a - z A - Z _ ] ( [ \w ] + ) ) $ / ) ;
182
+ const path = splitted [ 0 ] ;
183
+ const className = ! ! splitted [ 1 ] ? splitted [ 1 ] . substring ( 1 ) : 'default' ;
184
+
185
+ return { path, className } ;
186
+ } ) ;
182
187
}
183
188
184
189
get typeChecker ( ) : ts . TypeChecker | null {
@@ -301,13 +306,13 @@ export class AngularCompilerPlugin {
301
306
this . _contextElementDependencyConstructor = options . contextElementDependencyConstructor
302
307
|| require ( 'webpack/lib/dependencies/ContextElementDependency' ) ;
303
308
304
- // Use entryModule if available in options, otherwise resolve it from mainPath after program
309
+ // Use entryModules if available in options, otherwise resolve it from mainPath after program
305
310
// creation.
306
- if ( this . _options . entryModule ) {
307
- this . _entryModule = this . _options . entryModule ;
311
+ if ( this . _options . entryModules ) {
312
+ this . _entryModules = this . _options . entryModules || [ this . _options . entryModule ] ;
308
313
} else if ( this . _compilerOptions . entryModule ) {
309
- this . _entryModule = path . resolve ( this . _basePath ,
310
- this . _compilerOptions . entryModule as string ) ; // temporary cast for type issue
314
+ this . _entryModules = [ path . resolve ( this . _basePath ,
315
+ this . _compilerOptions . entryModule as string ) ] ; // temporary cast for type issue
311
316
}
312
317
313
318
// Set platform.
@@ -411,7 +416,7 @@ export class AngularCompilerPlugin {
411
416
this . _entryModule = resolveEntryModuleFromMain (
412
417
this . _mainPath , this . _compilerHost , this . _getTsProgram ( ) as ts . Program ) ;
413
418
414
- if ( ! this . entryModule && ! this . _compilerOptions . enableIvy ) {
419
+ if ( ! this . entryModules && ! this . _compilerOptions . enableIvy ) {
415
420
this . _warnings . push ( 'Lazy routes discovery is not enabled. '
416
421
+ 'Because there is neither an entryModule nor a '
417
422
+ 'statically analyzable bootstrap code in the main file.' ,
@@ -442,7 +447,7 @@ export class AngularCompilerPlugin {
442
447
let ngProgram : Program ;
443
448
444
449
if ( this . _JitMode ) {
445
- if ( ! this . entryModule ) {
450
+ if ( ! this . entryModules ) {
446
451
return { } ;
447
452
}
448
453
@@ -454,7 +459,8 @@ export class AngularCompilerPlugin {
454
459
} ) ;
455
460
timeEnd ( 'AngularCompilerPlugin._listLazyRoutesFromProgram.createProgram' ) ;
456
461
457
- entryRoute = this . entryModule . path + '#' + this . entryModule . className ;
462
+ const entryModule = this . entryModules [ 0 ] ;
463
+ entryRoute = entryModule . path + '#' + entryModule . className ;
458
464
} else {
459
465
ngProgram = this . _program as Program ;
460
466
}
@@ -851,9 +857,12 @@ export class AngularCompilerPlugin {
851
857
const isMainPath = ( fileName : string ) => fileName === (
852
858
this . _mainPath ? workaroundResolve ( this . _mainPath ) : this . _mainPath
853
859
) ;
854
- const getEntryModule = ( ) => this . entryModule
855
- ? { path : workaroundResolve ( this . entryModule . path ) , className : this . entryModule . className }
856
- : this . entryModule ;
860
+ // TODO: fix fn usage
861
+ const getEntryModules = ( ) => this . entryModules
862
+ ? this . entryModules . map ( ( entryModule ) => {
863
+ return { path : workaroundResolve ( entryModule . path ) , className : entryModule . className } ;
864
+ } )
865
+ : this . entryModules ;
857
866
const getLazyRoutes = ( ) => this . _lazyRoutes ;
858
867
const getTypeChecker = ( ) => ( this . _getTsProgram ( ) as ts . Program ) . getTypeChecker ( ) ;
859
868
@@ -873,15 +882,15 @@ export class AngularCompilerPlugin {
873
882
// This transform must go before replaceBootstrap because it looks for the entry module
874
883
// import, which will be replaced.
875
884
if ( this . _normalizedLocale ) {
876
- this . _transformers . push ( registerLocaleData ( isAppPath , getEntryModule ,
885
+ this . _transformers . push ( registerLocaleData ( isAppPath , getEntryModules ,
877
886
this . _normalizedLocale ) ) ;
878
887
}
879
888
880
889
if ( ! this . _JitMode ) {
881
890
// Replace bootstrap in browser AOT.
882
891
this . _transformers . push ( replaceBootstrap (
883
892
isAppPath ,
884
- getEntryModule ,
893
+ getEntryModules ,
885
894
getTypeChecker ,
886
895
! ! this . _compilerOptions . enableIvy ,
887
896
) ) ;
@@ -890,8 +899,8 @@ export class AngularCompilerPlugin {
890
899
this . _transformers . push ( exportLazyModuleMap ( isMainPath , getLazyRoutes ) ) ;
891
900
if ( ! this . _JitMode ) {
892
901
this . _transformers . push (
893
- exportNgFactory ( isMainPath , getEntryModule ) ,
894
- replaceServerBootstrap ( isMainPath , getEntryModule , getTypeChecker ) ) ;
902
+ exportNgFactory ( isMainPath , getEntryModules ) ,
903
+ replaceServerBootstrap ( isMainPath , getEntryModules , getTypeChecker ) ) ;
895
904
}
896
905
}
897
906
}
0 commit comments