Skip to content

Commit f848d08

Browse files
clydinKeen Yee Liau
authored and
Keen Yee Liau
committed
feat(@ngtools/webpack): disable sourcefile cache when not in watch mode
Requires Webpack 4.23.0+
1 parent 4059fe8 commit f848d08

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

packages/ngtools/webpack/src/angular_compiler_plugin.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,10 @@ export class AngularCompilerPlugin {
585585
}
586586

587587
// Registration hook for webpack plugin.
588-
apply(compiler: Compiler) {
588+
apply(compiler: Compiler & { watchMode?: boolean }) {
589+
// only present for webpack 4.23.0+, assume true otherwise
590+
const watchMode = compiler.watchMode === undefined ? true : compiler.watchMode;
591+
589592
// Decorate inputFileSystem to serve contents of CompilerHost.
590593
// Use decorated inputFileSystem in watchFileSystem.
591594
compiler.hooks.environment.tap('angular-compiler', () => {
@@ -629,6 +632,7 @@ export class AngularCompilerPlugin {
629632
this._compilerOptions,
630633
this._basePath,
631634
host,
635+
watchMode,
632636
);
633637

634638
// Create and set a new WebpackResourceLoader.

packages/ngtools/webpack/src/compiler_host.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export class WebpackCompilerHost implements ts.CompilerHost {
4545
private _options: ts.CompilerOptions,
4646
basePath: string,
4747
host: virtualFs.Host,
48+
private readonly cacheSourceFiles: boolean,
4849
) {
4950
this._syncHost = new virtualFs.SyncDelegateHost(host);
5051
this._memoryHost = new virtualFs.SyncDelegateHost(new virtualFs.SimpleMemoryHost());
@@ -260,7 +261,10 @@ export class WebpackCompilerHost implements ts.CompilerHost {
260261
const content = this.readFile(fileName);
261262
if (content !== undefined) {
262263
const sf = ts.createSourceFile(workaroundResolve(fileName), content, languageVersion, true);
263-
this._sourceFileCache.set(p, sf);
264+
265+
if (this.cacheSourceFiles) {
266+
this._sourceFileCache.set(p, sf);
267+
}
264268

265269
return sf;
266270
}

packages/ngtools/webpack/src/transformers/ast_helpers.ts

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export function createTypescriptContext(content: string) {
6262
compilerOptions,
6363
basePath,
6464
new virtualFs.SimpleMemoryHost(),
65+
false,
6566
);
6667

6768
// Add a dummy file to host content.

packages/ngtools/webpack/src/type_checker.ts

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export class TypeChecker {
5353
_compilerOptions,
5454
_basePath,
5555
host,
56+
true,
5657
);
5758
// We don't set a async resource loader on the compiler host because we only support
5859
// html templates, which are the only ones that can throw errors, and those can be loaded

0 commit comments

Comments
 (0)