Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 2 additions & 16 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,11 @@ export default function electron(options: ElectronOptions | ElectronOptions[]):
options.onstart.call(this, {
startup,
// Why not use Vite's built-in `/@vite/client` to implement Hot reload?
// Because Vite only inserts `/@vite/client` into the `*.html` entry file, the preload scripts are usually a `*.js` file.
// Because Vite only inserts `/@vite/client` into the `*.html` entry file.
// @see - https://github.com/vitejs/vite/blob/v5.2.11/packages/vite/src/node/server/middlewares/indexHtml.ts#L399
reload() {
if (process.electronApp) {
(server.hot || server.ws).send({ type: 'full-reload' })

// For Electron apps that don't need to use the renderer process.
startup.send('electron-vite&type=hot-reload')
} else {
startup()
}
Expand Down Expand Up @@ -168,10 +165,7 @@ export async function startup(
await startup.exit()

// Start Electron.app
process.electronApp = spawn(electronPath, argv, {
stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
...options,
})
process.electronApp = spawn(electronPath, argv, { stdio: 'inherit', ...options })

// Exit command after Electron.app exits
process.electronApp.once('exit', process.exit)
Expand All @@ -181,14 +175,6 @@ export async function startup(
process.once('exit', startup.exit)
}
}

startup.send = (message: string) => {
if (process.electronApp) {
// Based on { stdio: [,,, 'ipc'] }
process.electronApp.send?.(message)
}
}

startup.hookedProcessExit = false
startup.exit = async () => {
if (process.electronApp) {
Expand Down