electron-vite / vite-plugin-electron

:electron: Electron⚡️Vite core repo
https://github.com/electron-vite
MIT License
703 stars 57 forks source link

How to disable automatic opening of the electron window on `vite` #257

Open rafaellehmkuhl opened 1 month ago

rafaellehmkuhl commented 1 month ago

The project I work on supports usage as both an electron app as well as a web page, and most of the time, for practical purposes, we develop by previewing only the application as a web page, not dealing with the electron window.

We have a script command called dev which calls vite --host. We were previously using version 0.9.3 of this plugin, in which the electron window was not being opened by default, but since we updated to the latest version (0.28.8), the electron window is being opened by default with this same command.

Is there a way to disable it, so I can have a dedicated command (e.g.: dev:electron) that explicitly calls for the electron window to be opened (e.g.: vite --host && electron .)?

rafaellehmkuhl commented 1 month ago

My hacky workaround here for now:

On package.json:

"dev:electron": "ELECTRON=true vite --host"

On vite.config.ts:

// Check if we're running in Electron mode
const isElectron = process.env.ELECTRON === 'true'

export default defineConfig({
  plugins: [
    isElectron &&
      electron(...),
    ...
  ].filter(Boolean),
  ...