@@ -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 ,
@@ -471,15 +479,26 @@ export async function* serveWithVite(
471
479
async function handleUpdate (
472
480
normalizePath : ( id : string ) => string ,
473
481
generatedFiles : Map < string , OutputFileRecord > ,
482
+ assetFiles : Map < string , OutputAssetRecord > ,
474
483
server : ViteDevServer ,
475
484
serverOptions : NormalizedDevServerOptions ,
476
485
logger : BuilderContext [ 'logger' ] ,
477
486
componentStyles : Map < string , ComponentStyleRecord > ,
478
487
) : Promise < void > {
479
488
const updatedFiles : string [ ] = [ ] ;
480
- let destroyAngularServerAppCalled = false ;
489
+
490
+ // Invadate any updated asset
491
+ for ( const [ file , record ] of assetFiles ) {
492
+ if ( ! record . updated ) {
493
+ continue ;
494
+ }
495
+
496
+ record . updated = false ;
497
+ updatedFiles . push ( file ) ;
498
+ }
481
499
482
500
// Invalidate any updated files
501
+ let destroyAngularServerAppCalled = false ;
483
502
for ( const [ file , record ] of generatedFiles ) {
484
503
if ( ! record . updated ) {
485
504
continue ;
@@ -584,10 +603,16 @@ function updateResultRecord(
584
603
normalizePath : ( id : string ) => string ,
585
604
htmlIndexPath : string ,
586
605
generatedFiles : Map < string , OutputFileRecord > ,
606
+ assetFiles : Map < string , OutputAssetRecord > ,
587
607
componentStyles : Map < string , ComponentStyleRecord > ,
588
608
initial = false ,
589
609
) : void {
590
610
if ( file . origin === 'disk' ) {
611
+ assetFiles . set ( '/' + normalizePath ( outputPath ) , {
612
+ source : normalizePath ( file . inputPath ) ,
613
+ updated : ! initial ,
614
+ } ) ;
615
+
591
616
return ;
592
617
}
593
618
@@ -644,7 +669,7 @@ function updateResultRecord(
644
669
export async function setupServer (
645
670
serverOptions : NormalizedDevServerOptions ,
646
671
outputFiles : Map < string , OutputFileRecord > ,
647
- assets : Map < string , string > ,
672
+ assets : Map < string , OutputAssetRecord > ,
648
673
preserveSymlinks : boolean | undefined ,
649
674
externalMetadata : DevServerExternalResultMetadata ,
650
675
ssrMode : ServerSsrMode ,
@@ -743,7 +768,11 @@ export async function setupServer(
743
768
// The first two are required for Vite to function in prebundling mode (the default) and to load
744
769
// the Vite client-side code for browser reloading. These would be available by default but when
745
770
// the `allow` option is explicitly configured, they must be included manually.
746
- allow : [ cacheDir , join ( serverOptions . workspaceRoot , 'node_modules' ) , ...assets . values ( ) ] ,
771
+ allow : [
772
+ cacheDir ,
773
+ join ( serverOptions . workspaceRoot , 'node_modules' ) ,
774
+ ...[ ...assets . values ( ) ] . map ( ( { source } ) => source ) ,
775
+ ] ,
747
776
} ,
748
777
// This is needed when `externalDependencies` is used to prevent Vite load errors.
749
778
// NOTE: If Vite adds direct support for externals, this can be removed.
0 commit comments