@@ -15,6 +15,7 @@ import type { ViteDevServer } from '../../server'
1515import  {  createDebugger  }  from  '../../utils' 
1616import  {  getShortName  }  from  '../hmr' 
1717import  type  {  WebSocketClient  }  from  '../ws' 
18+ import  {  prepareError  }  from  '../middlewares/error' 
1819
1920const  debug  =  createDebugger ( 'vite:full-bundle-mode' ) 
2021
@@ -121,7 +122,13 @@ export class FullBundleDevEnvironment extends DevEnvironment {
121122    this . devEngine  =  await  dev ( rollupOptions ,  outputOptions ,  { 
122123      onHmrUpdates : ( result )  =>  { 
123124        if  ( result  instanceof  Error )  { 
124-           // TODO: handle error 
125+           // TODO: send to the specific client 
126+           for  ( const  client  of  this . clients . getAll ( ) )  { 
127+             client . send ( { 
128+               type : 'error' , 
129+               err : prepareError ( result ) , 
130+             } ) 
131+           } 
125132          return 
126133        } 
127134        const  {  updates,  changedFiles }  =  result 
@@ -138,6 +145,33 @@ export class FullBundleDevEnvironment extends DevEnvironment {
138145          this . handleHmrOutput ( client ,  changedFiles ,  update ) 
139146        } 
140147      } , 
148+       onOutput : ( result )  =>  { 
149+         if  ( result  instanceof  Error )  { 
150+           // TODO: handle error 
151+           return 
152+         } 
153+ 
154+         // TODO: make the API a bit more JS friendly 
155+         // NOTE: don't clear memoryFiles here as incremental build re-uses the files 
156+         for  ( const  asset  of  result . assets )  { 
157+           this . memoryFiles . set ( asset . fileName ,  ( )  =>  { 
158+             const  source  =  asset . source . inner 
159+             return  { 
160+               source, 
161+               etag : getEtag ( Buffer . from ( source ) ,  {  weak : true  } ) , 
162+             } 
163+           } ) 
164+         } 
165+         for  ( const  chunk  of  result . chunks )  { 
166+           this . memoryFiles . set ( chunk . fileName ,  ( )  =>  { 
167+             const  source  =  chunk . code 
168+             return  { 
169+               source, 
170+               etag : getEtag ( Buffer . from ( source ) ,  {  weak : true  } ) , 
171+             } 
172+           } ) 
173+         } 
174+       } , 
141175      watch : { 
142176        skipWrite : true , 
143177      } , 
@@ -249,31 +283,6 @@ export class FullBundleDevEnvironment extends DevEnvironment {
249283      implement : await  getHmrImplementation ( this . getTopLevelConfig ( ) ) , 
250284    } 
251285
252-     rolldownOptions . plugins  =  [ 
253-       rolldownOptions . plugins , 
254-       { 
255-         name : 'vite:full-bundle-mode:save-output' , 
256-         generateBundle : { 
257-           order : 'post' , 
258-           handler : ( _ ,  bundle )  =>  { 
259-             // NOTE: don't clear memoryFiles here as incremental build re-uses the files 
260-             for  ( const  outputFile  of  Object . values ( bundle ) )  { 
261-               this . memoryFiles . set ( outputFile . fileName ,  ( )  =>  { 
262-                 const  source  = 
263-                   outputFile . type  ===  'chunk' 
264-                     ? outputFile . code 
265-                     : outputFile . source 
266-                 return  { 
267-                   source, 
268-                   etag : getEtag ( Buffer . from ( source ) ,  {  weak : true  } ) , 
269-                 } 
270-               } ) 
271-             } 
272-           } , 
273-         } , 
274-       } , 
275-     ] 
276- 
277286    // set filenames to make output paths predictable so that `renderChunk` hook does not need to be used 
278287    if  ( Array . isArray ( rolldownOptions . output ) )  { 
279288      for  ( const  output  of  rolldownOptions . output )  { 
@@ -389,6 +398,10 @@ class Clients {
389398    return  this . clientToId . get ( client ) 
390399  } 
391400
401+   getAll ( ) : WebSocketClient [ ]  { 
402+     return  Array . from ( this . idToClient . values ( ) ) 
403+   } 
404+ 
392405  delete ( client : WebSocketClient ) : void { 
393406    const  id  =  this . clientToId . get ( client ) 
394407    if  ( id )  { 
0 commit comments