@@ -49,6 +49,11 @@ interface OutputFileRecord {
49
49
type : BuildOutputFileType ;
50
50
}
51
51
52
+ interface OutputAssetRecord {
53
+ source : string ;
54
+ updated : boolean ;
55
+ }
56
+
52
57
interface DevServerExternalResultMetadata extends Omit < ExternalResultMetadata , 'explicit' > {
53
58
explicitBrowser : string [ ] ;
54
59
explicitServer : string [ ] ;
@@ -168,7 +173,7 @@ export async function* serveWithVite(
168
173
let serverUrl : URL | undefined ;
169
174
let hadError = false ;
170
175
const generatedFiles = new Map < string , OutputFileRecord > ( ) ;
171
- const assetFiles = new Map < string , string > ( ) ;
176
+ const assetFiles = new Map < string , OutputAssetRecord > ( ) ;
172
177
const externalMetadata : DevServerExternalResultMetadata = {
173
178
implicitBrowser : [ ] ,
174
179
implicitServer : [ ] ,
@@ -229,19 +234,15 @@ export async function* serveWithVite(
229
234
assetFiles . clear ( ) ;
230
235
componentStyles . clear ( ) ;
231
236
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
- }
238
237
238
+ for ( const [ outputPath , file ] of Object . entries ( result . files ) ) {
239
239
updateResultRecord (
240
240
outputPath ,
241
241
file ,
242
242
normalizePath ,
243
243
htmlIndexPath ,
244
244
generatedFiles ,
245
+ assetFiles ,
245
246
componentStyles ,
246
247
// The initial build will not yet have a server setup
247
248
! server ,
@@ -265,13 +266,15 @@ export async function* serveWithVite(
265
266
generatedFiles . delete ( filePath ) ;
266
267
assetFiles . delete ( filePath ) ;
267
268
}
269
+
268
270
for ( const modified of result . modified ) {
269
271
updateResultRecord (
270
272
modified ,
271
273
result . files [ modified ] ,
272
274
normalizePath ,
273
275
htmlIndexPath ,
274
276
generatedFiles ,
277
+ assetFiles ,
275
278
componentStyles ,
276
279
) ;
277
280
}
@@ -282,6 +285,7 @@ export async function* serveWithVite(
282
285
normalizePath ,
283
286
htmlIndexPath ,
284
287
generatedFiles ,
288
+ assetFiles ,
285
289
componentStyles ,
286
290
) ;
287
291
}
@@ -352,12 +356,16 @@ export async function* serveWithVite(
352
356
if ( server ) {
353
357
// Update fs allow list to include any new assets from the build option.
354
358
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
+ ] ) ,
356
363
] ;
357
364
358
365
await handleUpdate (
359
366
normalizePath ,
360
367
generatedFiles ,
368
+ assetFiles ,
361
369
server ,
362
370
serverOptions ,
363
371
context . logger ,
@@ -470,15 +478,26 @@ export async function* serveWithVite(
470
478
async function handleUpdate (
471
479
normalizePath : ( id : string ) => string ,
472
480
generatedFiles : Map < string , OutputFileRecord > ,
481
+ assetFiles : Map < string , OutputAssetRecord > ,
473
482
server : ViteDevServer ,
474
483
serverOptions : NormalizedDevServerOptions ,
475
484
logger : BuilderContext [ 'logger' ] ,
476
485
componentStyles : Map < string , ComponentStyleRecord > ,
477
486
) : Promise < void > {
478
487
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
+ }
480
498
481
499
// Invalidate any updated files
500
+ let destroyAngularServerAppCalled = false ;
482
501
for ( const [ file , record ] of generatedFiles ) {
483
502
if ( ! record . updated ) {
484
503
continue ;
@@ -583,10 +602,16 @@ function updateResultRecord(
583
602
normalizePath : ( id : string ) => string ,
584
603
htmlIndexPath : string ,
585
604
generatedFiles : Map < string , OutputFileRecord > ,
605
+ assetFiles : Map < string , OutputAssetRecord > ,
586
606
componentStyles : Map < string , ComponentStyleRecord > ,
587
607
initial = false ,
588
608
) : void {
589
609
if ( file . origin === 'disk' ) {
610
+ assetFiles . set ( '/' + normalizePath ( outputPath ) , {
611
+ source : normalizePath ( file . inputPath ) ,
612
+ updated : ! initial ,
613
+ } ) ;
614
+
590
615
return ;
591
616
}
592
617
@@ -643,7 +668,7 @@ function updateResultRecord(
643
668
export async function setupServer (
644
669
serverOptions : NormalizedDevServerOptions ,
645
670
outputFiles : Map < string , OutputFileRecord > ,
646
- assets : Map < string , string > ,
671
+ assets : Map < string , OutputAssetRecord > ,
647
672
preserveSymlinks : boolean | undefined ,
648
673
externalMetadata : DevServerExternalResultMetadata ,
649
674
ssrMode : ServerSsrMode ,
@@ -730,7 +755,11 @@ export async function setupServer(
730
755
// The first two are required for Vite to function in prebundling mode (the default) and to load
731
756
// the Vite client-side code for browser reloading. These would be available by default but when
732
757
// 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
+ ] ,
734
763
} ,
735
764
// This is needed when `externalDependencies` is used to prevent Vite load errors.
736
765
// NOTE: If Vite adds direct support for externals, this can be removed.
0 commit comments