Electron Vite Build Tooling

5.0.0 · active · verified Tue Apr 21

electron-vite is a specialized build toolchain for Electron applications, leveraging the fast development experience of Vite. It streamlines the development process for Electron's main, preload, and renderer processes by providing pre-configured setups and a unified configuration API. The current stable version is 5.0.0, with beta releases for version 6.0.0 actively under development, indicating a moderate to rapid release cadence for new features and improvements. Key differentiators include its tight integration with Vite for all three Electron process types, simplified configuration, and out-of-the-box support for TypeScript and modern web development practices, making it a powerful alternative to more manual or less integrated build setups.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a typical `electron.vite.config.ts` configuration, setting up separate build processes for Electron's main, preload, and renderer scripts using `defineConfig`.

import { defineConfig } from 'electron-vite'
import { resolve } from 'path'

export default defineConfig({
  main: {
    // Main process build configuration
    build: {
      lib: {
        entry: 'src/main/index.ts',
        formats: ['cjs']
      },
      outDir: 'dist/main',
      rollupOptions: {
        external: ['electron'] // Prevent bundling electron itself
      }
    }
  },
  preload: {
    // Preload script build configuration
    build: {
      lib: {
        entry: 'src/preload/index.ts',
        formats: ['cjs']
      },
      outDir: 'dist/preload',
      rollupOptions: {
        external: ['electron']
      }
    }
  },
  renderer: {
    // Renderer process build configuration
    root: '.', // Relative to electron.vite.config.ts
    build: {
      outDir: 'dist/renderer',
      rollupOptions: {
        // Example: externalize some renderer dependencies if needed
        external: []
      }
    }
  }
})

view raw JSON →