Configures electron-vite build system for Electron main, preload, and renderer processes. Use when: modifying electron.vite.config.ts, adding Vite plugins, configuring path aliases, adjusting build outputs, troubleshooting HMR or build errors, adding environment variables, or understanding how the three-process Electron build works.
This project uses electron-vite 5 (not plain Vite) — a single electron.vite.config.ts configures three separate Vite builds for Electron's main, preload, and renderer processes. The renderer uses Vite 7 with React, Tailwind CSS 4, TanStack Router, and React Compiler.
The unified config lives at electron.vite.config.ts:
import { defineConfig } from "electron-vite";
import react from "@vitejs/plugin-react";
import tailwindcss from "@tailwindcss/vite";
import { tanstackRouter } from "@tanstack/router-plugin/vite";
import { resolve } from "path";
import { viteStaticCopy } from "vite-plugin-static-copy";
export default defineConfig({
main: {
build: {
outDir: "dist/main",
rollupOptions: { input: { index: resolve(__dirname, "src/main.ts") } },
},
resolve: { alias: { "@": resolve(__dirname, "./src") } },
},
preload: {
build: {
outDir: "dist/preload",
rollupOptions: { input: { index: resolve(__dirname, "src/preload.ts") } },
},
},
renderer: {
root: ".",
build: {
outDir: "dist/renderer",
rollupOptions: { input: { index: resolve(__dirname, "index.html") } },
},
publicDir: false,
plugins: [
viteStaticCopy({ targets: [{ src: "assets", dest: "." }] }),
tanstackRouter({ target: "react", autoCodeSplitting: true }),
tailwindcss(),
react({ babel: { plugins: ["babel-plugin-react-compiler"] } }),
],
resolve: {
preserveSymlinks: true,
alias: { "@": resolve(__dirname, "./src") },
},
},
});
| Concept | Detail |
|---|---|
| Three builds | main (Node.js), preload (bridge), renderer (browser/React) |
| Entry points | src/main.ts, src/preload.ts, index.html → src/renderer.ts |
| Output dirs | dist/main/, dist/preload/, dist/renderer/ |
| Path alias | @/ → ./src/ (configured in main + renderer, NOT preload) |
| Dev server | http://localhost:5173 (renderer only) |
| CSS | Tailwind CSS 4 via @tailwindcss/vite plugin — no tailwind.config file |
| Routing | TanStack Router plugin auto-generates src/routeTree.gen.ts |
| React Compiler | Enabled via babel-plugin-react-compiler in the React plugin |
Add to the renderer.plugins array. Plugin order matters — TanStack Router and static copy should run before React.
Must be added in BOTH electron.vite.config.ts (resolve.alias) AND tsconfig.json (paths):
// electron.vite.config.ts — main and renderer sections