Skip to content

Commit 213802b

Browse files
clydinfilipesilva
authored andcommitted
feat(@ngtools/webpack): adjust changed file extensions based on usage
1 parent a40e801 commit 213802b

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

packages/@ngtools/webpack/src/angular_compiler_plugin.ts

+23-5
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ export class AngularCompilerPlugin implements Tapable {
103103
private _platform: PLATFORM;
104104
private _JitMode = false;
105105
private _emitSkipped = true;
106+
private _changedFileExtensions = new Set(['ts', 'html', 'css']);
106107

107108
// Webpack plugin.
108109
private _firstRun = true;
@@ -292,9 +293,22 @@ export class AngularCompilerPlugin implements Tapable {
292293
.filter(k => this._compilerHost.fileExists(k));
293294
}
294295

296+
updateChangedFileExtensions(extension: string) {
297+
if (extension) {
298+
this._changedFileExtensions.add(extension);
299+
}
300+
}
301+
295302
private _getChangedCompilationFiles() {
296303
return this._compilerHost.getChangedFilePaths()
297-
.filter(k => /\.(?:ts|html|css|scss|sass|less|styl)$/.test(k));
304+
.filter(k => {
305+
for (const ext of this._changedFileExtensions) {
306+
if (k.endsWith(ext)) {
307+
return true;
308+
}
309+
}
310+
return false;
311+
});
298312
}
299313

300314
private _createOrUpdateProgram() {
@@ -877,12 +891,16 @@ export class AngularCompilerPlugin implements Tapable {
877891
const resourceImports = findResources(sourceFile)
878892
.map((resourceReplacement) => resourceReplacement.resourcePaths)
879893
.reduce((prev, curr) => prev.concat(curr), [])
880-
.map((resourcePath) => path.resolve(path.dirname(resolvedFileName), resourcePath))
881-
.reduce((prev, curr) =>
882-
prev.concat(...this.getResourceDependencies(curr)), []);
894+
.map((resourcePath) => path.resolve(path.dirname(resolvedFileName), resourcePath));
883895

884896
// These paths are meant to be used by the loader so we must denormalize them.
885-
return [...esImports, ...resourceImports].map((p) => this._compilerHost.denormalizePath(p));
897+
const uniqueDependencies = new Set([
898+
...esImports,
899+
...resourceImports,
900+
...this.getResourceDependencies(resolvedFileName)
901+
].map((p) => this._compilerHost.denormalizePath(p)));
902+
903+
return [...uniqueDependencies];
886904
}
887905

888906
getResourceDependencies(fileName: string): string[] {

packages/@ngtools/webpack/src/loader.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,10 @@ export function ngcLoader(this: LoaderContext & { _compilation: any }, source: s
589589
if (sourceFileName.endsWith('.ts')) {
590590
result.errorDependencies.forEach(dep => this.addDependency(dep));
591591
const dependencies = plugin.getDependencies(sourceFileName);
592-
dependencies.forEach(dep => this.addDependency(dep));
592+
dependencies.forEach(dep => {
593+
plugin.updateChangedFileExtensions(path.extname(dep));
594+
this.addDependency(dep);
595+
});
593596
}
594597

595598
// NgFactory files depend on the component template, but we can't know what that file

0 commit comments

Comments
 (0)