@@ -90,6 +90,7 @@ export interface AngularCompilerPluginOptions {
90
90
compilerOptions ?: ts . CompilerOptions ;
91
91
92
92
host ?: virtualFs . Host < fs . Stats > ;
93
+ platformTransformers ?: ts . TransformerFactory < ts . SourceFile > [ ] ;
93
94
}
94
95
95
96
export enum PLATFORM {
@@ -115,6 +116,7 @@ export class AngularCompilerPlugin {
115
116
private _mainPath : string | undefined ;
116
117
private _basePath : string ;
117
118
private _transformers : ts . TransformerFactory < ts . SourceFile > [ ] = [ ] ;
119
+ private _platformTransformers : ts . TransformerFactory < ts . SourceFile > [ ] | null = null ;
118
120
private _platform : PLATFORM ;
119
121
private _JitMode = false ;
120
122
private _emitSkipped = true ;
@@ -260,6 +262,11 @@ export class AngularCompilerPlugin {
260
262
this . _forkTypeChecker = options . forkTypeChecker ;
261
263
}
262
264
265
+ // Add custom platform transformers.
266
+ if ( options . platformTransformers !== undefined ) {
267
+ this . _platformTransformers = options . platformTransformers ;
268
+ }
269
+
263
270
// Create the webpack compiler host.
264
271
const webpackCompilerHost = new WebpackCompilerHost (
265
272
this . _compilerOptions ,
@@ -757,25 +764,29 @@ export class AngularCompilerPlugin {
757
764
this . _transformers . push ( removeDecorators ( isAppPath , getTypeChecker ) ) ;
758
765
}
759
766
760
- if ( this . _platform === PLATFORM . Browser ) {
761
- // If we have a locale, auto import the locale data file.
762
- // This transform must go before replaceBootstrap because it looks for the entry module
763
- // import, which will be replaced.
764
- if ( this . _normalizedLocale ) {
765
- this . _transformers . push ( registerLocaleData ( isAppPath , getEntryModule ,
766
- this . _normalizedLocale ) ) ;
767
- }
767
+ if ( this . _platformTransformers !== null ) {
768
+ this . _transformers . push ( ...this . _platformTransformers ) ;
769
+ } else {
770
+ if ( this . _platform === PLATFORM . Browser ) {
771
+ // If we have a locale, auto import the locale data file.
772
+ // This transform must go before replaceBootstrap because it looks for the entry module
773
+ // import, which will be replaced.
774
+ if ( this . _normalizedLocale ) {
775
+ this . _transformers . push ( registerLocaleData ( isAppPath , getEntryModule ,
776
+ this . _normalizedLocale ) ) ;
777
+ }
768
778
769
- if ( ! this . _JitMode ) {
770
- // Replace bootstrap in browser AOT.
771
- this . _transformers . push ( replaceBootstrap ( isAppPath , getEntryModule , getTypeChecker ) ) ;
772
- }
773
- } else if ( this . _platform === PLATFORM . Server ) {
774
- this . _transformers . push ( exportLazyModuleMap ( isMainPath , getLazyRoutes ) ) ;
775
- if ( ! this . _JitMode ) {
776
- this . _transformers . push (
777
- exportNgFactory ( isMainPath , getEntryModule ) ,
778
- replaceServerBootstrap ( isMainPath , getEntryModule , getTypeChecker ) ) ;
779
+ if ( ! this . _JitMode ) {
780
+ // Replace bootstrap in browser AOT.
781
+ this . _transformers . push ( replaceBootstrap ( isAppPath , getEntryModule , getTypeChecker ) ) ;
782
+ }
783
+ } else if ( this . _platform === PLATFORM . Server ) {
784
+ this . _transformers . push ( exportLazyModuleMap ( isMainPath , getLazyRoutes ) ) ;
785
+ if ( ! this . _JitMode ) {
786
+ this . _transformers . push (
787
+ exportNgFactory ( isMainPath , getEntryModule ) ,
788
+ replaceServerBootstrap ( isMainPath , getEntryModule , getTypeChecker ) ) ;
789
+ }
779
790
}
780
791
}
781
792
}
0 commit comments