Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions packages/angular/build/src/builders/application/build-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ function* emitOutputResults(
},
};

let hasCssUpdates = false;

// Initially assume all previous output files have been removed
const removedOutputFiles = new Map(previousOutputInfo);
for (const file of outputFiles) {
Expand All @@ -316,8 +318,10 @@ function* emitOutputResults(
}

if (needFile) {
// Updates to non-JS files must signal an update with the dev server
if (!/(?:\.m?js|\.map)$/.test(file.path)) {
if (file.path.endsWith('.css')) {
hasCssUpdates = true;
} else if (!/(?:\.m?js|\.map)$/.test(file.path)) {
// Updates to non-JS files must signal an update with the dev server
incrementalResult.background = false;
}

Expand Down Expand Up @@ -345,6 +349,8 @@ function* emitOutputResults(
continue;
}

hasCssUpdates ||= destination.endsWith('.css');

incrementalResult.files[destination] = {
type: BuildOutputFileType.Browser,
inputPath: source,
Expand All @@ -369,6 +375,21 @@ function* emitOutputResults(
// If there are template updates and the incremental update was background only, a component
// update is possible.
if (hasTemplateUpdates && incrementalResult.background) {
// Template changes may be accompanied by stylesheet changes and these should also be updated hot when possible.
if (hasCssUpdates) {
const styleResult: IncrementalResult = {
kind: ResultKind.Incremental,
added: incrementalResult.added.filter(isCssFilePath),
removed: incrementalResult.removed.filter(({ path }) => isCssFilePath(path)),
modified: incrementalResult.modified.filter(isCssFilePath),
files: Object.fromEntries(
Object.entries(incrementalResult.files).filter(([path]) => isCssFilePath(path)),
),
};

yield styleResult;
}

const updateResult: ComponentUpdateResult = {
kind: ResultKind.ComponentUpdate,
updates: Array.from(templateUpdates, ([id, content]) => ({
Expand All @@ -381,3 +402,7 @@ function* emitOutputResults(
yield updateResult;
}
}

function isCssFilePath(filePath: string): boolean {
return /\.css(?:\.map)?$/i.test(filePath);
}
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ function handleUpdate(
type: 'update',
updates,
});
logger.info('HMR update sent to client(s).');
logger.info('Stylesheet update sent to client(s).');

return;
}
Expand Down
Loading