diff --git a/packages/angular/build/src/builders/application/build-action.ts b/packages/angular/build/src/builders/application/build-action.ts index 0ded5bb5ef28..c59863f0ebf5 100644 --- a/packages/angular/build/src/builders/application/build-action.ts +++ b/packages/angular/build/src/builders/application/build-action.ts @@ -9,7 +9,7 @@ import { BuilderContext } from '@angular-devkit/architect'; import { existsSync } from 'node:fs'; import path from 'node:path'; -import { BuildOutputFileType } from '../../tools/esbuild/bundler-context'; +import { BuildOutputFile, BuildOutputFileType } from '../../tools/esbuild/bundler-context'; import { ExecutionResult, RebuildState } from '../../tools/esbuild/bundler-execution-result'; import { shutdownSassWorkerPool } from '../../tools/esbuild/stylesheets/sass-language'; import { logMessages, withNoProgress, withSpinner } from '../../tools/esbuild/utils'; @@ -327,8 +327,7 @@ function* emitOutputResults( if (needFile) { 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 + } else if (!canBackgroundUpdate(file)) { incrementalResult.background = false; } @@ -422,3 +421,15 @@ function* emitOutputResults( function isCssFilePath(filePath: string): boolean { return /\.css(?:\.map)?$/i.test(filePath); } + +function canBackgroundUpdate(file: BuildOutputFile): boolean { + // Files in the output root are not served and do not affect the + // application available with the development server. + if (file.type === BuildOutputFileType.Root) { + return true; + } + + // Updates to non-JS files must signal an update with the dev server + // except the service worker configuration which is special cased. + return /(?:\.m?js|\.map)$/.test(file.path) || file.path === 'ngsw.json'; +}