@@ -92,11 +92,14 @@ export default function electron(options: ElectronOptions | ElectronOptions[]):
9292 options . onstart . call ( this , {
9393 startup,
9494 // Why not use Vite's built-in `/@vite/client` to implement Hot reload?
95- // Because Vite only inserts `/@vite/client` into the `*.html` entry file.
95+ // Because Vite only inserts `/@vite/client` into the `*.html` entry file, the preload scripts are usually a `*.js` file .
9696 // @see - https://github.com/vitejs/vite/blob/v5.2.11/packages/vite/src/node/server/middlewares/indexHtml.ts#L399
9797 reload ( ) {
9898 if ( process . electronApp ) {
9999 ( server . hot || server . ws ) . send ( { type : 'full-reload' } )
100+
101+ // For Electron apps that don't need to use the renderer process.
102+ startup . send ( 'electron-vite&type=hot-reload' )
100103 } else {
101104 startup ( )
102105 }
@@ -165,7 +168,10 @@ export async function startup(
165168 await startup . exit ( )
166169
167170 // Start Electron.app
168- process . electronApp = spawn ( electronPath , argv , { stdio : 'inherit' , ...options } )
171+ process . electronApp = spawn ( electronPath , argv , {
172+ stdio : [ 'inherit' , 'inherit' , 'inherit' , 'ipc' ] ,
173+ ...options ,
174+ } )
169175
170176 // Exit command after Electron.app exits
171177 process . electronApp . once ( 'exit' , process . exit )
@@ -175,6 +181,14 @@ export async function startup(
175181 process . once ( 'exit' , startup . exit )
176182 }
177183}
184+
185+ startup . send = ( message : string ) => {
186+ if ( process . electronApp ) {
187+ // Based on { stdio: [,,, 'ipc'] }
188+ process . electronApp . send ?.( message )
189+ }
190+ }
191+
178192startup . hookedProcessExit = false
179193startup . exit = async ( ) => {
180194 if ( process . electronApp ) {
0 commit comments