@@ -90,6 +90,7 @@ export interface AngularCompilerPluginOptions {
9090 compilerOptions ?: ts . CompilerOptions ;
9191
9292 host ?: virtualFs . Host < fs . Stats > ;
93+ platformTransformers ?: ts . TransformerFactory < ts . SourceFile > [ ] ;
9394}
9495
9596export enum PLATFORM {
@@ -115,6 +116,7 @@ export class AngularCompilerPlugin {
115116 private _mainPath : string | undefined ;
116117 private _basePath : string ;
117118 private _transformers : ts . TransformerFactory < ts . SourceFile > [ ] = [ ] ;
119+ private _platformTransformers : ts . TransformerFactory < ts . SourceFile > [ ] | null = null ;
118120 private _platform : PLATFORM ;
119121 private _JitMode = false ;
120122 private _emitSkipped = true ;
@@ -260,6 +262,11 @@ export class AngularCompilerPlugin {
260262 this . _forkTypeChecker = options . forkTypeChecker ;
261263 }
262264
265+ // Add custom platform transformers.
266+ if ( options . platformTransformers !== undefined ) {
267+ this . _platformTransformers = options . platformTransformers ;
268+ }
269+
263270 // Create the webpack compiler host.
264271 const webpackCompilerHost = new WebpackCompilerHost (
265272 this . _compilerOptions ,
@@ -757,25 +764,29 @@ export class AngularCompilerPlugin {
757764 this . _transformers . push ( removeDecorators ( isAppPath , getTypeChecker ) ) ;
758765 }
759766
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+ }
768778
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+ }
779790 }
780791 }
781792 }
0 commit comments