Skip to content

Commit 391bdf5

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

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

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

Lines changed: 8 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,15 @@ export class AngularCompilerPlugin implements Tapable {
292293
.filter(k => this._compilerHost.fileExists(k));
293294
}
294295

296+
updateChangedFileExtensions(extensions: Set<string>) {
297+
for (const ext of extensions) {
298+
this._changedFileExtensions.add(ext[0] === '.' ? ext.substr(1) : ext);
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 => new RegExp(`\\.(?:${[...this._changedFileExtensions].join('|')})$`).test(k));
298305
}
299306

300307
private _createOrUpdateProgram() {

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

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,8 @@ export function ngcLoader(this: LoaderContext & { _compilation: any }, source: s
581581
result.sourceMap = sourceMap;
582582
}
583583

584+
const dependencyExtensions = new Set<string>();
585+
584586
// Manually add the dependencies for TS files.
585587
// Type only imports will be stripped out by compilation so we need to add them as
586588
// as dependencies.
@@ -589,7 +591,12 @@ export function ngcLoader(this: LoaderContext & { _compilation: any }, source: s
589591
if (sourceFileName.endsWith('.ts')) {
590592
result.errorDependencies.forEach(dep => this.addDependency(dep));
591593
const dependencies = plugin.getDependencies(sourceFileName);
592-
dependencies.forEach(dep => this.addDependency(dep));
594+
dependencies.forEach(dep => {
595+
if (path.extname(dep)) {
596+
dependencyExtensions.add(path.extname(dep));
597+
}
598+
this.addDependency(dep);
599+
});
593600
}
594601

595602
// NgFactory files depend on the component template, but we can't know what that file
@@ -601,7 +608,12 @@ export function ngcLoader(this: LoaderContext & { _compilation: any }, source: s
601608
const originalFile = sourceFileName.replace(ngFactoryRe, '.ts');
602609
this.addDependency(originalFile);
603610
const origDependencies = plugin.getDependencies(originalFile);
604-
origDependencies.forEach(dep => this.addDependency(dep));
611+
origDependencies.forEach(dep => {
612+
if (path.extname(dep)) {
613+
dependencyExtensions.add(path.extname(dep));
614+
}
615+
this.addDependency(dep);
616+
});
605617
}
606618

607619
// NgStyle files depend on the style file they represent.
@@ -611,9 +623,16 @@ export function ngcLoader(this: LoaderContext & { _compilation: any }, source: s
611623
if (ngStyleRe.test(sourceFileName)) {
612624
const styleFile = sourceFileName.replace(ngStyleRe, '');
613625
const styleDependencies = plugin.getResourceDependencies(styleFile);
614-
styleDependencies.forEach(dep => this.addDependency(dep));
626+
styleDependencies.forEach(dep => {
627+
if (path.extname(dep)) {
628+
dependencyExtensions.add(path.extname(dep));
629+
}
630+
this.addDependency(dep);
631+
});
615632
}
616633

634+
plugin.updateChangedFileExtensions(dependencyExtensions);
635+
617636
timeEnd(timeLabel);
618637
cb(null, result.outputText, result.sourceMap);
619638
})

0 commit comments

Comments
 (0)