Skip to content

Commit

Permalink
fix(vite-plugin-angular): add listeners to watch file add/deletion of…
Browse files Browse the repository at this point in the history
… files for compilation
  • Loading branch information
brandonroberts committed Aug 1, 2022
1 parent aadf018 commit 58d6732
Showing 1 changed file with 30 additions and 27 deletions.
57 changes: 30 additions & 27 deletions packages/vite-plugin-angular/src/lib/angular-vite-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,39 +91,18 @@ export function angular(
},
};
},
configureServer(server) {
server.watcher.on('add', setupCompilation);
server.watcher.on('unlink', setupCompilation);
},
async buildStart() {
const { options: tsCompilerOptions, rootNames: rn } =
compilerCli.readConfiguration(pluginOptions.tsconfig, {
enableIvy: true,
noEmitOnError: false,
suppressOutputPathCheck: true,
outDir: undefined,
inlineSources: !isProd,
inlineSourceMap: !isProd,
sourceMap: false,
mapRoot: undefined,
sourceRoot: undefined,
declaration: false,
declarationMap: false,
allowEmptyCodegenFiles: false,
annotationsAs: 'decorators',
enableResourceInlining: false,
});

rootNames = rn;
compilerOptions = tsCompilerOptions;
host = ts.createIncrementalCompilerHost(compilerOptions);

// Setup source file caching and reuse cache from previous compilation if present
let cache = new SourceFileCache();
setupCompilation();

// Only store cache if in watch mode
if (watchMode) {
sourceFileCache = cache;
augmentHostWithCaching(host, sourceFileCache);
}

augmentHostWithCaching(host, cache);

await buildAndAnalyze();
},
async handleHotUpdate(ctx) {
Expand Down Expand Up @@ -290,6 +269,30 @@ export function angular(
},
];

function setupCompilation() {
const { options: tsCompilerOptions, rootNames: rn } =
compilerCli.readConfiguration(pluginOptions.tsconfig, {
enableIvy: true,
noEmitOnError: false,
suppressOutputPathCheck: true,
outDir: undefined,
inlineSources: !isProd,
inlineSourceMap: !isProd,
sourceMap: false,
mapRoot: undefined,
sourceRoot: undefined,
declaration: false,
declarationMap: false,
allowEmptyCodegenFiles: false,
annotationsAs: 'decorators',
enableResourceInlining: false,
});

rootNames = rn;
compilerOptions = tsCompilerOptions;
host = ts.createIncrementalCompilerHost(compilerOptions);
}

/**
* Creates a new NgtscProgram to analyze/re-analyze
* the source files and create a file emitter.
Expand Down

0 comments on commit 58d6732

Please sign in to comment.