Skip to content

Commit

Permalink
feat(vite-plugin-angular): add tsTransformers config (#213)
Browse files Browse the repository at this point in the history
Closes #210
  • Loading branch information
ch1ffa authored Jan 16, 2023
1 parent 48d652d commit e733cd1
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions packages/vite-plugin-angular/src/lib/angular-vite-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ export interface PluginOptions {
tsconfig?: string;
workspaceRoot?: string;
inlineStylesExtension?: string;
advanced?: {
/**
* Custom TypeScript transformers that are run before Angular compilation
*/
tsTransformers?: (
| ts.TransformerFactory<ts.SourceFile>
| ts.CustomTransformerFactory
)[];
};
}

interface EmitFileResult {
Expand Down Expand Up @@ -49,6 +58,9 @@ export function angular(options?: PluginOptions): Plugin[] {
: './tsconfig.app.json'),
workspaceRoot: options?.workspaceRoot ?? process.cwd(),
inlineStylesExtension: options?.inlineStylesExtension ?? 'css',
advanced: {
tsTransformers: options?.advanced?.tsTransformers ?? [],
},
};

// The file emitter created during `onStart` that will be used during the build in `onLoad` callbacks for TS files
Expand All @@ -69,10 +81,10 @@ export function angular(options?: PluginOptions): Plugin[] {
let host: ts.CompilerHost;
let nextProgram: NgtscProgram;
let builderProgram: ts.EmitAndSemanticDiagnosticsBuilderProgram;
let watchMode: boolean = false;
let sourceFileCache = new SourceFileCache();
let isProd = process.env['NODE_ENV'] === 'production';
let isTest = process.env['NODE_ENV'] === 'test' || !!process.env['VITEST'];
let watchMode = false;
const sourceFileCache = new SourceFileCache();
const isProd = process.env['NODE_ENV'] === 'production';
const isTest = process.env['NODE_ENV'] === 'test' || !!process.env['VITEST'];
let viteServer: ViteDevServer | undefined;
let cssPlugin: Plugin | undefined;

Expand Down Expand Up @@ -158,7 +170,7 @@ export function angular(options?: PluginOptions): Plugin[] {
return ctx.modules;
}

let mods: ModuleNode[] = [];
const mods: ModuleNode[] = [];
ctx.modules.forEach((mod) => {
mod.importers.forEach((imp) => {
sourceFileCache.invalidate(imp.id);
Expand Down Expand Up @@ -443,7 +455,10 @@ export function angular(options?: PluginOptions): Plugin[] {
builder,
mergeTransformers(
{
before: [replaceBootstrap(getTypeChecker)],
before: [
replaceBootstrap(getTypeChecker),
...pluginOptions.advanced.tsTransformers,
],
},
angularCompiler.prepareEmit().transformers
),
Expand Down

0 comments on commit e733cd1

Please sign in to comment.