Skip to content

Commit ac4da98

Browse files
committed
feat(@ngtools/webpack): adjust changed file extensions based on usage
1 parent cfd007c commit ac4da98

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

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

Lines changed: 15 additions & 1 deletion
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() {

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

Lines changed: 12 additions & 3 deletions
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
@@ -601,7 +604,10 @@ export function ngcLoader(this: LoaderContext & { _compilation: any }, source: s
601604
const originalFile = sourceFileName.replace(ngFactoryRe, '.ts');
602605
this.addDependency(originalFile);
603606
const origDependencies = plugin.getDependencies(originalFile);
604-
origDependencies.forEach(dep => this.addDependency(dep));
607+
origDependencies.forEach(dep => {
608+
plugin.updateChangedFileExtensions(path.extname(dep));
609+
this.addDependency(dep);
610+
});
605611
}
606612

607613
// NgStyle files depend on the style file they represent.
@@ -611,7 +617,10 @@ export function ngcLoader(this: LoaderContext & { _compilation: any }, source: s
611617
if (ngStyleRe.test(sourceFileName)) {
612618
const styleFile = sourceFileName.replace(ngStyleRe, '');
613619
const styleDependencies = plugin.getResourceDependencies(styleFile);
614-
styleDependencies.forEach(dep => this.addDependency(dep));
620+
styleDependencies.forEach(dep => {
621+
plugin.updateChangedFileExtensions(path.extname(dep));
622+
this.addDependency(dep);
623+
});
615624
}
616625

617626
timeEnd(timeLabel);

0 commit comments

Comments
 (0)