
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
electron-vite-toolkit
Advanced tools
A comprehensive toolkit for building Electron applications with Vite, featuring multi-window support, hot reload, and TypeScript integration
Note: This toolkit has been mainly created to use with electron-vite-tailwind-monorepo-template.
A comprehensive toolkit for building Electron applications with Vite, featuring multi-window support, hot reload, and TypeScript integration.
npm install electron-vite-toolkit
# or
yarn add electron-vite-toolkit
# or
pnpm add electron-vite-toolkit
scripts/electron-entry.mjs):import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { buildWindowsConfig } from 'electron-vite-toolkit/windows-config';
(async () => {
const scriptDir = path.dirname(fileURLToPath(import.meta.url));
const windowsPath = path.resolve(scriptDir, '../app/windows');
const config = buildWindowsConfig({ windowsPath });
const mainDist = await import('../app/main/dist/index.js');
const { initApp } = mainDist;
initApp(config);
})();
your-project/
βββ app/
β βββ main/
β β βββ src/
β β βββ index.ts # Main process entry
β βββ windows/
β βββ main/
β β βββ renderer/ # Main window renderer
β β βββ preload/ # Main window preload
β βββ settings/
β βββ renderer/ # Settings window renderer
β βββ preload/ # Settings window preload
βββ scripts/
βββ electron-entry.mjs
Start development server:
npx electron-vite-toolkit dev
# or
npx electron-vite-toolkit start
The CLI now supports configurable paths for better project flexibility:
# Use default windows path (app/windows)
npx electron-vite-toolkit dev
# Specify custom windows path
npx electron-vite-toolkit dev --windows-path src/windows
npx electron-vite-toolkit dev -w custom/windows/path
# Show help
npx electron-vite-toolkit --help
npx electron-vite-toolkit -h
Available Options:
--windows-path, -w <path>: Path to the windows directory (default: app/windows)--help, -h: Show help messageExamples:
# Standard usage
npx electron-vite-toolkit dev
# Custom windows directory
npx electron-vite-toolkit dev --windows-path src/electron/windows
# Using short flag
npx electron-vite-toolkit start -w ./windows
# Different project structure
npx electron-vite-toolkit dev --windows-path packages/renderer/windows
buildWindowsConfig(options)Builds configuration for all discovered windows based on the current environment.
Parameters:
options.windowsPath (string): Path to the windows directoryReturns:
WindowsConfig: Configuration object containing window definitionsExample:
import { buildWindowsConfig } from 'electron-vite-toolkit/windows-config';
const config = buildWindowsConfig({
windowsPath: path.resolve(__dirname, '../app/windows'),
});
// In development: uses dev server URLs
// In production: uses built file paths
startDevMode(options?)Starts the development server with hot reload support.
Parameters:
options.windowsPath (string, optional): Path to the windows directory. Defaults to 'app/windows'Examples:
import { startDevMode } from 'electron-vite-toolkit';
// Use default windows path
await startDevMode();
// Use custom windows path
await startDevMode({
windowsPath: 'src/windows',
});
// Absolute path
await startDevMode({
windowsPath: '/path/to/project/windows',
});
The toolkit exports TypeScript interfaces for better development experience:
import { DevModeOptions, WindowConfig, WindowsConfig } from 'electron-vite-toolkit';
// Development mode options
const devOptions: DevModeOptions = {
windowsPath: 'src/windows',
};
// Window configuration type
const windowConfig: WindowConfig = {
renderer: new URL('http://localhost:5173'),
preload: { path: '/path/to/preload.mjs' },
};
The toolkit automatically manages these environment variables:
VITE_DEV_SERVER_URL - Main window dev server URLVITE_DEV_SERVER_URL_{WINDOW_NAME} - Additional window dev server URLs (e.g., VITE_DEV_SERVER_URL_SETTINGS)MODE - Current mode ('development' or 'production')NODE_ENV - Node environment ('development' or 'production')The toolkit automatically discovers windows in your configured windows directory (default: app/windows). Each folder represents a window:
{windowsPath}/
βββ main/ # Main window (required)
β βββ renderer/ # Vite-powered renderer process
β βββ preload/ # Preload script
βββ settings/ # Additional window
βββ renderer/ # Vite-powered renderer process
βββ preload/ # Preload script
The windows directory can be customized through CLI options or API calls:
app/windows--windows-path custom/windowsstartDevMode({ windowsPath: 'custom/windows' })mainConfig(options?)Creates a Vite configuration for the Electron main process with hot reload support.
Parameters:
options (UserConfig, optional): Additional Vite configuration options to mergeExample:
// vite.config.js for main process
import { mainConfig } from 'electron-vite-toolkit/vite/main';
export default mainConfig({
// your custom config
build: {
outDir: 'custom-dist',
},
});
createRendererViteConfig(options?)Creates a Vite configuration for React renderer processes with Tailwind CSS support.
Parameters:
options (UserConfig, optional): Additional Vite configuration options to mergeExample:
// vite.config.js for renderer
import { createRendererViteConfig } from 'electron-vite-toolkit/vite/renderer';
export default createRendererViteConfig({
// your custom config
plugins: [
// additional plugins
],
});
createPreloadViteConfig(options?)Creates a Vite configuration for preload scripts with hot reload and API exposure support.
Parameters:
options (UserConfig, optional): Additional Vite configuration options to mergeExample:
// vite.config.js for preload
import { createPreloadViteConfig } from 'electron-vite-toolkit/vite/preload';
export default createPreloadViteConfig({
// your custom config
});
Use the provided Vite configurations for optimal development experience with pre-configured settings for each process type.
You can customize window behavior by building the configuration programmatically:
import { buildWindowsConfig } from 'electron-vite-toolkit/windows-config';
// Build configuration with custom windows path
const config = buildWindowsConfig({
windowsPath: path.resolve(__dirname, 'custom/windows'),
});
// Access individual window configurations
const mainWindow = config.windows.main;
const settingsWindow = config.windows.settings;
// Use in your main process
export async function initApp(windowsConfig: WindowsConfig): Promise<void> {
// Your custom initialization logic
// Access all discovered windows through windowsConfig.windows
Object.entries(windowsConfig.windows).forEach(([name, windowConfig]) => {
console.log(`Window ${name}:`, windowConfig);
});
}
The toolkit automatically handles different modes:
dist directories with optimized bundlesYou can integrate the development mode into your own scripts:
import { startDevMode } from 'electron-vite-toolkit';
// Custom development setup
async function customDev() {
await startDevMode({
windowsPath: process.env.WINDOWS_PATH || 'app/windows',
});
}
// Run with environment variables
// WINDOWS_PATH=src/windows node custom-dev.js
If you encounter port conflicts, the toolkit automatically finds available ports. You can also set RANDOM_PORTS=true for random port allocation:
RANDOM_PORTS=true npx electron-vite-toolkit dev
If the toolkit can't find your windows directory:
# Debug with explicit path
npx electron-vite-toolkit dev --windows-path ./src/electron/windows
# Check if directory exists
ls -la ./src/electron/windows
Make sure your import paths are correct and use the proper file extensions (.mjs for ES modules).
If development servers fail to start:
renderer subdirectoryIf builds fail:
tsconfig.json is properly configurednode_modules and reinstallingContributions are welcome! Please check the main repository for contribution guidelines.
This toolkit is based on the excellent work by cawa-93 in the original vite-electron-builder repository. Special thanks to the contributors and the Electron community for their ongoing support and inspiration.
MIT - see LICENSE file for details.
FAQs
A comprehensive toolkit for building Electron applications with Vite, featuring multi-window support, hot reload, and TypeScript integration
We found that electron-vite-toolkit demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Β It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.