@@ -57,7 +57,7 @@ export interface AngularCompilerPluginOptions {
57
57
sourceMap ?: boolean ;
58
58
tsConfigPath : string ;
59
59
basePath ?: string ;
60
- entryModule ?: string ;
60
+ entryModule ?: string | string [ ] ;
61
61
mainPath ?: string ;
62
62
skipCodeGeneration ?: boolean ;
63
63
hostReplacementPaths ?: { [ path : string ] : string } ;
@@ -95,7 +95,7 @@ export class AngularCompilerPlugin implements Tapable {
95
95
// Contains `moduleImportPath#exportName` => `fullModulePath`.
96
96
private _lazyRoutes : LazyRouteMap = Object . create ( null ) ;
97
97
private _tsConfigPath : string ;
98
- private _entryModule : string ;
98
+ private _entryModule : string [ ] ;
99
99
private _mainPath : string | undefined ;
100
100
private _basePath : string ;
101
101
private _transformers : ts . TransformerFactory < ts . SourceFile > [ ] = [ ] ;
@@ -129,14 +129,17 @@ export class AngularCompilerPlugin implements Tapable {
129
129
130
130
get options ( ) { return this . _options ; }
131
131
get done ( ) { return this . _donePromise ; }
132
- get entryModule ( ) {
132
+ get entryModule ( ) : { path : string , className : string } [ ] {
133
133
if ( ! this . _entryModule ) {
134
134
return undefined ;
135
135
}
136
- const splitted = this . _entryModule . split ( '#' ) ;
137
- const path = splitted [ 0 ] ;
138
- const className = splitted [ 1 ] || 'default' ;
139
- return { path, className } ;
136
+
137
+ return this . _entryModule . map ( ( entryModule ) => {
138
+ const splitted = entryModule . split ( '#' ) ;
139
+ const path = splitted [ 0 ] ;
140
+ const className = splitted [ 1 ] || 'default' ;
141
+ return { path, className } ;
142
+ } ) ;
140
143
}
141
144
142
145
static isSupported ( ) {
@@ -266,10 +269,16 @@ export class AngularCompilerPlugin implements Tapable {
266
269
// Use entryModule if available in options, otherwise resolve it from mainPath after program
267
270
// creation.
268
271
if ( this . _options . entryModule ) {
269
- this . _entryModule = this . _options . entryModule ;
272
+ this . _entryModule = Array . isArray ( this . _options . entryModule ) ?
273
+ this . _options . entryModule : [ this . _options . entryModule ] ;
270
274
} else if ( this . _compilerOptions . entryModule ) {
271
- this . _entryModule = path . resolve ( this . _basePath ,
272
- this . _compilerOptions . entryModule ) ;
275
+ if ( Array . isArray ( this . _compilerOptions . entryModule ) ) {
276
+ this . _entryModule = ( < string [ ] > this . _compilerOptions . entryModule ) . map ( ( entryModule ) => {
277
+ return path . resolve ( this . _basePath , entryModule ) ;
278
+ } ) ;
279
+ } else {
280
+ this . _entryModule = [ path . resolve ( this . _basePath , this . _compilerOptions . entryModule ) ] ;
281
+ }
273
282
}
274
283
275
284
// Set platform.
@@ -355,14 +364,20 @@ export class AngularCompilerPlugin implements Tapable {
355
364
private _getLazyRoutesFromNgtools ( ) {
356
365
try {
357
366
time ( 'AngularCompilerPlugin._getLazyRoutesFromNgtools' ) ;
358
- const result = __NGTOOLS_PRIVATE_API_2 . listLazyRoutes ( {
359
- program : this . _getTsProgram ( ) ,
360
- host : this . _compilerHost ,
361
- angularCompilerOptions : Object . assign ( { } , this . _compilerOptions , {
362
- // genDir seems to still be needed in @angular \compiler-cli\src\compiler_host.js:226.
363
- genDir : ''
364
- } ) ,
365
- entryModule : this . _entryModule
367
+ const result = { } ;
368
+ if ( ! Array . isArray ( this . _entryModule ) ) {
369
+ this . _entryModule = [ this . _entryModule ] ;
370
+ }
371
+ this . _entryModule . forEach ( ( entryModule ) => {
372
+ Object . assign ( result , __NGTOOLS_PRIVATE_API_2 . listLazyRoutes ( {
373
+ program : this . _getTsProgram ( ) ,
374
+ host : this . _compilerHost ,
375
+ angularCompilerOptions : Object . assign ( { } , this . _compilerOptions , {
376
+ // genDir seems to still be needed in @angular \compiler-cli\src\compiler_host.js:226.
377
+ genDir : ''
378
+ } ) ,
379
+ entryModule : entryModule
380
+ } ) ) ;
366
381
} ) ;
367
382
timeEnd ( 'AngularCompilerPlugin._getLazyRoutesFromNgtools' ) ;
368
383
return result ;
@@ -636,7 +651,10 @@ export class AngularCompilerPlugin implements Tapable {
636
651
const isAppPath = ( fileName : string ) =>
637
652
! fileName . endsWith ( '.ngfactory.ts' ) && ! fileName . endsWith ( '.ngstyle.ts' ) ;
638
653
const isMainPath = ( fileName : string ) => fileName === this . _mainPath ;
639
- const getEntryModule = ( ) => this . entryModule ;
654
+ const getEntryModule = ( i : number ) => ( ) => this . entryModule [ i ] ;
655
+ const entryModulesIdxs = Array . from (
656
+ Array ( this . entryModule ? this . entryModule . length : 0 ) . keys ( )
657
+ ) ;
640
658
const getLazyRoutes = ( ) => this . _lazyRoutes ;
641
659
const getTypeChecker = ( ) => this . _getTsProgram ( ) . getTypeChecker ( ) ;
642
660
@@ -653,18 +671,24 @@ export class AngularCompilerPlugin implements Tapable {
653
671
// This transform must go before replaceBootstrap because it looks for the entry module
654
672
// import, which will be replaced.
655
673
if ( this . _compilerOptions . i18nInLocale ) {
656
- this . _transformers . push ( registerLocaleData ( isAppPath , getEntryModule ,
657
- this . _compilerOptions . i18nInLocale ) ) ;
674
+ entryModulesIdxs . forEach ( ( idx ) => {
675
+ this . _transformers . push ( registerLocaleData ( isAppPath , getEntryModule ( idx ) ,
676
+ this . _compilerOptions . i18nInLocale ) ) ;
677
+ } ) ;
658
678
}
659
679
660
680
if ( ! this . _JitMode ) {
661
681
// Replace bootstrap in browser AOT.
662
- this . _transformers . push ( replaceBootstrap ( isAppPath , getEntryModule , getTypeChecker ) ) ;
682
+ entryModulesIdxs . forEach ( ( idx ) => {
683
+ this . _transformers . push ( replaceBootstrap ( isAppPath , getEntryModule ( idx ) , getTypeChecker ) ) ;
684
+ } ) ;
663
685
}
664
686
} else if ( this . _platform === PLATFORM . Server ) {
665
687
this . _transformers . push ( exportLazyModuleMap ( isMainPath , getLazyRoutes ) ) ;
666
688
if ( ! this . _JitMode ) {
667
- this . _transformers . push ( exportNgFactory ( isMainPath , getEntryModule ) ) ;
689
+ entryModulesIdxs . forEach ( ( idx ) => {
690
+ this . _transformers . push ( exportNgFactory ( isMainPath , getEntryModule ( idx ) ) ) ;
691
+ } ) ;
668
692
}
669
693
}
670
694
}
0 commit comments