Skip to content
This repository has been archived by the owner on Apr 9, 2022. It is now read-only.

Commit

Permalink
feat(@ngtools/webpack): allow custom platform transformers
Browse files Browse the repository at this point in the history
Supersedes #960
  • Loading branch information
filipesilva authored and clydin committed May 29, 2018
1 parent b2c3752 commit 67181f5
Showing 1 changed file with 29 additions and 18 deletions.
47 changes: 29 additions & 18 deletions packages/ngtools/webpack/src/angular_compiler_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export interface AngularCompilerPluginOptions {
compilerOptions?: ts.CompilerOptions;

host?: virtualFs.Host<fs.Stats>;
platformTransformers?: ts.TransformerFactory<ts.SourceFile>[];
}

export enum PLATFORM {
Expand All @@ -115,6 +116,7 @@ export class AngularCompilerPlugin {
private _mainPath: string | undefined;
private _basePath: string;
private _transformers: ts.TransformerFactory<ts.SourceFile>[] = [];
private _platformTransformers: ts.TransformerFactory<ts.SourceFile>[] | null = null;
private _platform: PLATFORM;
private _JitMode = false;
private _emitSkipped = true;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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));
}
}
}
}
Expand Down

0 comments on commit 67181f5

Please sign in to comment.