Registry / devops / vite-plugin-electron

vite-plugin-electron

JSON →
library0.29.1jsnpmunverified

A Vite plugin that integrates Electron main process and preload scripts into the Vite build pipeline, supporting hot reload for main process via electron-rebuild (HMR). Current stable version is 0.29.1. The plugin automatically starts Electron after Vite server is ready and allows configuring entry files, build options, and external dependencies. Actively maintained with frequent releases. Key differentiator: full HMR support for Electron main process, unlike alternatives like electron-vite which require separate builds.

npm install vite-plugin-electron
INSTALL
IMPORT
SIG · VITE-PLUGIN-ELECTR
V
vite-plugin-electron
devopsjavascriptv0.29.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

vitePluginElectron
import vitePluginElectron from 'vite-plugin-electron'
const vitePluginElectron = require('vite-plugin-electron')
ESM-only since v0.28; default export is the plugin factory function.
defineConfig
import { defineConfig } from 'vite-plugin-electron'
import { defineConfig } from 'vite'
The plugin re-exports defineConfig for convenience; using vite's own defineConfig also works but may miss plugin-specific types.
type VitePluginElectronOptions
import type { VitePluginElectronOptions } from 'vite-plugin-electron'
import { VitePluginElectronOptions } from 'vite-plugin-electron'
Type-only import to avoid runtime side effects; recommended for TypeScript users.

Configures Vite to build Electron main process and preload scripts with HMR support, using two plugin entries.

import { defineConfig } from 'vite'; import electron from 'vite-plugin-electron'; import renderer from 'vite-plugin-electron-renderer'; import path from 'path'; export default defineConfig({ plugins: [ electron([ { entry: 'electron/main.ts', onstart(args) { args.startup(); }, vite: { build: { outDir: 'dist-electron', rollupOptions: { external: ['electron'], }, }, }, }, { entry: 'electron/preload.ts', onstart(args) { args.reload(); }, vite: { build: { outDir: 'dist-electron', }, }, }, ]), renderer(), ], server: { port: 5173, }, });
Debug
Known issues
breakingv1.0.0-beta.1 drops Vite 7 support and requires Vite 8.
fix
Upgrade to Vite 8 or stay on vite-plugin-electron <1.0.0-beta.1
affects: >=1.0.0-beta.1
breakingIn v0.28, the plugin switched to ESM-only; CommonJS require() no longer works.
fix
Use import syntax or dynamic import() from CJS code.
affects: >=0.28.0
deprecatedThe 'main' and 'preload' options in plugin config are deprecated in favor of an array of entry objects.
fix
Use array configuration with 'entry' and 'onstart' fields.
affects: >=0.28.0
gotchaHot reload may not work on Windows if the Electron process exits prematurely; the process must be started via args.startup().
fix
Call args.startup() in onstart callback to ensure proper process management.
affects: >=0.28.0
gotchaIf external dependencies are not listed in rollupOptions.external, they may be bundled incorrectly causing runtime errors.
fix
Add 'electron' and other native modules to external in the Vite build config.
affects: >=0.28.0
Errors
Common errors & fixes
Error: Cannot find module 'electron'
Electron is not listed as external in the Vite build config for main process.
fix
Add 'electron' to rollupOptions.external in the plugin's vite config.
Error: startup is not a function
Using an older version of the plugin (<0.28) or incorrect onstart signature.
fix
Upgrade to >=0.28 and ensure onstart receives args object with startup method.
Module not found: Error: Can't resolve 'fs'
Default Vite config does not mark Node built-ins as external for Electron main process.
fix
Add 'builtinModules' from 'module' module to external in rollupOptions.
Electron app does not close on Ctrl+C in terminal
Process is not properly killed on Vite server shutdown.
fix
Use args.startup() to manage lifecycle; consider using the 'onstart' callback to gracefully shut down.
Upgrade
Version history
0.29.1latest on npm
Audit
Dependencies
vite-plugin-electron-rendereroptionalNeeded for renderer process integration; peer dependency marked as optional in later versions.
Agent activity
4 hits · last 30 days
node
4
Resources
vite-plugin-electron — npm install vite-plugin-electron · libregistry