@@ -484,32 +484,39 @@ export async function createServer(
484
484
return setPackageData ( id , pkg )
485
485
}
486
486
487
- watcher . on ( 'change' , async ( file ) => {
488
- file = normalizePath ( file )
489
- if ( file . endsWith ( '/package.json' ) ) {
490
- return invalidatePackageData ( packageCache , file )
491
- }
492
- // invalidate module graph cache on file change
493
- moduleGraph . onFileChange ( file )
487
+ const onHMRUpdate = async ( file : string , configOnly : boolean ) => {
494
488
if ( serverConfig . hmr !== false ) {
495
489
try {
496
- await handleHMRUpdate ( file , server )
490
+ await handleHMRUpdate ( file , server , configOnly )
497
491
} catch ( err ) {
498
492
ws . send ( {
499
493
type : 'error' ,
500
494
err : prepareError ( err ) ,
501
495
} )
502
496
}
503
497
}
504
- } )
498
+ }
505
499
506
- watcher . on ( 'add' , ( file ) => {
507
- handleFileAddUnlink ( normalizePath ( file ) , server )
508
- } )
509
- watcher . on ( 'unlink' , ( file ) => {
510
- handleFileAddUnlink ( normalizePath ( file ) , server )
500
+ const onFileAddUnlink = async ( file : string ) => {
501
+ file = normalizePath ( file )
502
+ await handleFileAddUnlink ( file , server )
503
+ await onHMRUpdate ( file , true )
504
+ }
505
+
506
+ watcher . on ( 'change' , async ( file ) => {
507
+ file = normalizePath ( file )
508
+ if ( file . endsWith ( '/package.json' ) ) {
509
+ return invalidatePackageData ( packageCache , file )
510
+ }
511
+ // invalidate module graph cache on file change
512
+ moduleGraph . onFileChange ( file )
513
+
514
+ await onHMRUpdate ( file , false )
511
515
} )
512
516
517
+ watcher . on ( 'add' , onFileAddUnlink )
518
+ watcher . on ( 'unlink' , onFileAddUnlink )
519
+
513
520
ws . on ( 'vite:invalidate' , async ( { path, message } : InvalidatePayload ) => {
514
521
const mod = moduleGraph . urlToModuleMap . get ( path )
515
522
if ( mod && mod . isSelfAccepting && mod . lastHMRTimestamp > 0 ) {
0 commit comments