Skip to content
Closed
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
11 changes: 11 additions & 0 deletions packages/angular/build/src/builders/application/build-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,25 @@ async function emitOutputResult(
}

// Template updates only exist if no other changes have occurred
// To support Tailwind CSS the global styles.css build output is included in the update so it can be checked for changes
// as the file watcher is only capable of detecting changes to the raw styles.css file.
if (templateUpdates?.size) {
const globalStyles = outputFiles.find((f) => f.path === 'styles.css');
const updateResult: ComponentUpdateResult = {
kind: ResultKind.ComponentUpdate,
updates: Array.from(templateUpdates).map(([id, content]) => ({
type: 'template',
id,
content,
})),
globalStyles: globalStyles
? {
origin: 'memory',
hash: globalStyles.hash,
type: globalStyles.type,
contents: globalStyles.contents,
}
: undefined,
};

return updateResult;
Expand Down
1 change: 1 addition & 0 deletions packages/angular/build/src/builders/application/results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,5 @@ export interface ComponentUpdateResult extends BaseResult {
type: 'style' | 'template';
content: string;
}[];
globalStyles?: MemoryFile;
}
38 changes: 37 additions & 1 deletion packages/angular/build/src/builders/dev-server/vite-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { EsbuildLoaderOption, getDepOptimizationConfig } from '../../tools/vite/
import { loadProxyConfiguration, normalizeSourceMaps } from '../../utils';
import { useComponentStyleHmr, useComponentTemplateHmr } from '../../utils/environment-options';
import { loadEsmModule } from '../../utils/load-esm';
import { Result, ResultFile, ResultKind } from '../application/results';
import { MemoryFile, Result, ResultFile, ResultKind } from '../application/results';
import {
type ApplicationBuilderInternalOptions,
BuildOutputFileType,
Expand Down Expand Up @@ -265,6 +265,11 @@ export async function* serveWithVite(
});
}
}

if (result.globalStyles) {
updateGlobalStyles(result.globalStyles, generatedFiles, server);
}

context.logger.info('Component update sent to client(s).');
continue;
default:
Expand Down Expand Up @@ -611,6 +616,37 @@ function analyzeResultFiles(
}
}

function updateGlobalStyles(
file: MemoryFile,
generatedFiles: Map<string, OutputFileRecord>,
server: ViteDevServer,
) {
const stylesUrl = '/styles.css';
const styleHash = generatedFiles.get(stylesUrl);
if (file.hash !== styleHash?.hash) {
generatedFiles.set(stylesUrl, {
contents: file.contents,
size: file.contents.byteLength,
hash: file.hash,
updated: true,
type: file.type,
servable: true,
});
const timestamp = Date.now();
server.ws.send({
type: 'update',
updates: [
{
type: 'css-update' as const,
timestamp,
path: stylesUrl,
acceptedPath: stylesUrl,
},
],
});
}
}

export async function setupServer(
serverOptions: NormalizedDevServerOptions,
outputFiles: Map<string, OutputFileRecord>,
Expand Down
Loading