diff --git a/packages/ngtools/webpack/src/angular_compiler_plugin.ts b/packages/ngtools/webpack/src/angular_compiler_plugin.ts index 3b42bd1605..2f802ee27d 100644 --- a/packages/ngtools/webpack/src/angular_compiler_plugin.ts +++ b/packages/ngtools/webpack/src/angular_compiler_plugin.ts @@ -90,6 +90,7 @@ export interface AngularCompilerPluginOptions { compilerOptions?: ts.CompilerOptions; host?: virtualFs.Host; + platformTransformers?: ts.TransformerFactory[]; } export enum PLATFORM { @@ -115,6 +116,7 @@ export class AngularCompilerPlugin { private _mainPath: string | undefined; private _basePath: string; private _transformers: ts.TransformerFactory[] = []; + private _platformTransformers: ts.TransformerFactory[] | null = null; private _platform: PLATFORM; private _JitMode = false; private _emitSkipped = true; @@ -260,6 +262,11 @@ export class AngularCompilerPlugin { this._forkTypeChecker = options.forkTypeChecker; } + // Add custom platform transformers. + if (options.platformTransformers !== undefined) { + this._platformTransformers = options.platformTransformers; + } + // Create the webpack compiler host. const webpackCompilerHost = new WebpackCompilerHost( this._compilerOptions, @@ -757,25 +764,29 @@ export class AngularCompilerPlugin { this._transformers.push(removeDecorators(isAppPath, getTypeChecker)); } - if (this._platform === PLATFORM.Browser) { - // If we have a locale, auto import the locale data file. - // This transform must go before replaceBootstrap because it looks for the entry module - // import, which will be replaced. - if (this._normalizedLocale) { - this._transformers.push(registerLocaleData(isAppPath, getEntryModule, - this._normalizedLocale)); - } + if (this._platformTransformers !== null) { + this._transformers.push(...this._platformTransformers); + } else { + if (this._platform === PLATFORM.Browser) { + // If we have a locale, auto import the locale data file. + // This transform must go before replaceBootstrap because it looks for the entry module + // import, which will be replaced. + if (this._normalizedLocale) { + this._transformers.push(registerLocaleData(isAppPath, getEntryModule, + this._normalizedLocale)); + } - if (!this._JitMode) { - // Replace bootstrap in browser AOT. - this._transformers.push(replaceBootstrap(isAppPath, getEntryModule, getTypeChecker)); - } - } else if (this._platform === PLATFORM.Server) { - this._transformers.push(exportLazyModuleMap(isMainPath, getLazyRoutes)); - if (!this._JitMode) { - this._transformers.push( - exportNgFactory(isMainPath, getEntryModule), - replaceServerBootstrap(isMainPath, getEntryModule, getTypeChecker)); + if (!this._JitMode) { + // Replace bootstrap in browser AOT. + this._transformers.push(replaceBootstrap(isAppPath, getEntryModule, getTypeChecker)); + } + } else if (this._platform === PLATFORM.Server) { + this._transformers.push(exportLazyModuleMap(isMainPath, getLazyRoutes)); + if (!this._JitMode) { + this._transformers.push( + exportNgFactory(isMainPath, getEntryModule), + replaceServerBootstrap(isMainPath, getEntryModule, getTypeChecker)); + } } } }