@@ -4,6 +4,7 @@ import type {
44  Logger , 
55  WebSocketData , 
66  ServerStartParams , 
7+   DevServerCoreConfig , 
78}  from  '@web/dev-server-core' ; 
89import  WebSocket  from  'ws' ; 
910import  type  {  Context  }  from  'koa' ; 
@@ -47,9 +48,10 @@ export class HmrPlugin implements Plugin {
4748  protected  _dependencyTree : Map < string ,  HmrModule >  =  new  Map ( ) ; 
4849  protected  _webSockets ?: WebSocketsManager ; 
4950  protected  _logger ?: Logger ; 
51+   protected  _config ?: DevServerCoreConfig ; 
5052
5153  /** @inheritDoc  */ 
52-   async  serverStart ( {  webSockets,  fileWatcher,  logger } : ServerStartParams )  { 
54+   async  serverStart ( {  webSockets,  fileWatcher,  logger,  config  } : ServerStartParams )  { 
5355    if  ( ! fileWatcher )  { 
5456      throw  new  Error ( 'Cannot use HMR when watch mode is disabled.' ) ; 
5557    } 
@@ -58,6 +60,7 @@ export class HmrPlugin implements Plugin {
5860      throw  new  Error ( 'Cannot use HMR when web sockets are disabled.' ) ; 
5961    } 
6062
63+     this . _config  =  config ; 
6164    this . _webSockets  =  webSockets ; 
6265    this . _logger  =  logger ; 
6366
@@ -159,8 +162,14 @@ export class HmrPlugin implements Plugin {
159162   * Fired when a file has changed. 
160163   * @param  path Module path which has changed 
161164   */ 
162-   protected  _onFileChanged ( path : string ) : void { 
163-     this . _triggerUpdate ( path ) ; 
165+   protected  _onFileChanged ( filePath : string ) : void { 
166+     if  ( ! this . _config ?. rootDir )  { 
167+       return ; 
168+     } 
169+ 
170+     const  relativePath  =  pathUtil . relative ( this . _config . rootDir ,  filePath ) ; 
171+     const  browserPath  =  relativePath . split ( pathUtil . sep ) . join ( '/' ) ; 
172+     this . _triggerUpdate ( `/${ browserPath }  ) ; 
164173  } 
165174
166175  /** 
0 commit comments