@@ -49,6 +49,11 @@ interface OutputFileRecord {
4949 type : BuildOutputFileType ;
5050}
5151
52+ interface OutputAssetRecord {
53+ source : string ;
54+ updated : boolean ;
55+ }
56+
5257interface DevServerExternalResultMetadata extends Omit < ExternalResultMetadata , 'explicit' > {
5358 explicitBrowser : string [ ] ;
5459 explicitServer : string [ ] ;
@@ -168,7 +173,7 @@ export async function* serveWithVite(
168173 let serverUrl : URL | undefined ;
169174 let hadError = false ;
170175 const generatedFiles = new Map < string , OutputFileRecord > ( ) ;
171- const assetFiles = new Map < string , string > ( ) ;
176+ const assetFiles = new Map < string , OutputAssetRecord > ( ) ;
172177 const externalMetadata : DevServerExternalResultMetadata = {
173178 implicitBrowser : [ ] ,
174179 implicitServer : [ ] ,
@@ -229,19 +234,15 @@ export async function* serveWithVite(
229234 assetFiles . clear ( ) ;
230235 componentStyles . clear ( ) ;
231236 generatedFiles . clear ( ) ;
232- for ( const entry of Object . entries ( result . files ) ) {
233- const [ outputPath , file ] = entry ;
234- if ( file . origin === 'disk' ) {
235- assetFiles . set ( '/' + normalizePath ( outputPath ) , normalizePath ( file . inputPath ) ) ;
236- continue ;
237- }
238237
238+ for ( const [ outputPath , file ] of Object . entries ( result . files ) ) {
239239 updateResultRecord (
240240 outputPath ,
241241 file ,
242242 normalizePath ,
243243 htmlIndexPath ,
244244 generatedFiles ,
245+ assetFiles ,
245246 componentStyles ,
246247 // The initial build will not yet have a server setup
247248 ! server ,
@@ -265,13 +266,15 @@ export async function* serveWithVite(
265266 generatedFiles . delete ( filePath ) ;
266267 assetFiles . delete ( filePath ) ;
267268 }
269+
268270 for ( const modified of result . modified ) {
269271 updateResultRecord (
270272 modified ,
271273 result . files [ modified ] ,
272274 normalizePath ,
273275 htmlIndexPath ,
274276 generatedFiles ,
277+ assetFiles ,
275278 componentStyles ,
276279 ) ;
277280 }
@@ -282,6 +285,7 @@ export async function* serveWithVite(
282285 normalizePath ,
283286 htmlIndexPath ,
284287 generatedFiles ,
288+ assetFiles ,
285289 componentStyles ,
286290 ) ;
287291 }
@@ -352,12 +356,16 @@ export async function* serveWithVite(
352356 if ( server ) {
353357 // Update fs allow list to include any new assets from the build option.
354358 server . config . server . fs . allow = [
355- ...new Set ( [ ...server . config . server . fs . allow , ...assetFiles . values ( ) ] ) ,
359+ ...new Set ( [
360+ ...server . config . server . fs . allow ,
361+ ...[ ...assetFiles . values ( ) ] . map ( ( { source } ) => source ) ,
362+ ] ) ,
356363 ] ;
357364
358365 await handleUpdate (
359366 normalizePath ,
360367 generatedFiles ,
368+ assetFiles ,
361369 server ,
362370 serverOptions ,
363371 context . logger ,
@@ -470,15 +478,26 @@ export async function* serveWithVite(
470478async function handleUpdate (
471479 normalizePath : ( id : string ) => string ,
472480 generatedFiles : Map < string , OutputFileRecord > ,
481+ assetFiles : Map < string , OutputAssetRecord > ,
473482 server : ViteDevServer ,
474483 serverOptions : NormalizedDevServerOptions ,
475484 logger : BuilderContext [ 'logger' ] ,
476485 componentStyles : Map < string , ComponentStyleRecord > ,
477486) : Promise < void > {
478487 const updatedFiles : string [ ] = [ ] ;
479- let destroyAngularServerAppCalled = false ;
488+
489+ // Invadate any updated asset
490+ for ( const [ file , record ] of assetFiles ) {
491+ if ( ! record . updated ) {
492+ continue ;
493+ }
494+
495+ record . updated = false ;
496+ updatedFiles . push ( file ) ;
497+ }
480498
481499 // Invalidate any updated files
500+ let destroyAngularServerAppCalled = false ;
482501 for ( const [ file , record ] of generatedFiles ) {
483502 if ( ! record . updated ) {
484503 continue ;
@@ -583,10 +602,16 @@ function updateResultRecord(
583602 normalizePath : ( id : string ) => string ,
584603 htmlIndexPath : string ,
585604 generatedFiles : Map < string , OutputFileRecord > ,
605+ assetFiles : Map < string , OutputAssetRecord > ,
586606 componentStyles : Map < string , ComponentStyleRecord > ,
587607 initial = false ,
588608) : void {
589609 if ( file . origin === 'disk' ) {
610+ assetFiles . set ( '/' + normalizePath ( outputPath ) , {
611+ source : normalizePath ( file . inputPath ) ,
612+ updated : ! initial ,
613+ } ) ;
614+
590615 return ;
591616 }
592617
@@ -643,7 +668,7 @@ function updateResultRecord(
643668export async function setupServer (
644669 serverOptions : NormalizedDevServerOptions ,
645670 outputFiles : Map < string , OutputFileRecord > ,
646- assets : Map < string , string > ,
671+ assets : Map < string , OutputAssetRecord > ,
647672 preserveSymlinks : boolean | undefined ,
648673 externalMetadata : DevServerExternalResultMetadata ,
649674 ssrMode : ServerSsrMode ,
@@ -730,7 +755,11 @@ export async function setupServer(
730755 // The first two are required for Vite to function in prebundling mode (the default) and to load
731756 // the Vite client-side code for browser reloading. These would be available by default but when
732757 // the `allow` option is explicitly configured, they must be included manually.
733- allow : [ cacheDir , join ( serverOptions . workspaceRoot , 'node_modules' ) , ...assets . values ( ) ] ,
758+ allow : [
759+ cacheDir ,
760+ join ( serverOptions . workspaceRoot , 'node_modules' ) ,
761+ ...[ ...assets . values ( ) ] . map ( ( { source } ) => source ) ,
762+ ] ,
734763 } ,
735764 // This is needed when `externalDependencies` is used to prevent Vite load errors.
736765 // NOTE: If Vite adds direct support for externals, this can be removed.
0 commit comments