Top Related Projects
A Foundation for Scalable Cross-Platform Apps
Secure boilerplate for Electron app based on Vite. TypeScript + Vue/React/Angular/Svelte/Vanilla
Easily Build Your Vue.js App For Desktop With Electron
Clone to try a simple Electron app
:electron: A complete tool for building and publishing Electron applications
Build smaller, faster, and more secure desktop and mobile applications with a web frontend.
Quick Overview
Electron-vite-react is a template for building Electron applications using Vite and React. It provides a modern, fast development environment for creating cross-platform desktop applications with web technologies, combining the power of Electron, the speed of Vite, and the flexibility of React.
Pros
- Fast development and hot reloading thanks to Vite's build system
- Cross-platform compatibility (Windows, macOS, Linux) through Electron
- Modern React setup with TypeScript support
- Pre-configured with ESLint, Prettier, and testing tools
Cons
- Learning curve for developers new to Electron or Vite
- Potential performance overhead compared to native desktop applications
- Larger application size due to bundling Chromium with Electron
- Limited access to some low-level system features compared to native apps
Getting Started
-
Clone the repository:
git clone https://github.com/electron-vite/electron-vite-react.git cd electron-vite-react
-
Install dependencies:
npm install
-
Start the development server:
npm run dev
-
To build for production:
npm run build
Code Examples
- Main process entry point (main/index.ts):
import { app, BrowserWindow, shell, ipcMain } from 'electron'
import { release } from 'node:os'
import { join } from 'node:path'
// Create the main application window
function createWindow() {
const win = new BrowserWindow({
title: 'Main window',
webPreferences: {
preload: join(__dirname, '../preload/index.js'),
},
})
if (app.isPackaged) {
win.loadFile(join(__dirname, '../renderer/index.html'))
} else {
win.loadURL(process.env['VITE_DEV_SERVER_URL'])
}
}
app.whenReady().then(createWindow)
- Renderer process entry point (src/main.tsx):
import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App'
import './index.css'
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
<React.StrictMode>
<App />
</React.StrictMode>,
)
- Example component (src/components/Greet.tsx):
import { useState } from 'react'
export default function Greet() {
const [count, setCount] = useState(0)
return (
<div className="card">
<button onClick={() => setCount((count) => count + 1)}>
count is {count}
</button>
</div>
)
}
These examples showcase the basic structure of an Electron app with Vite and React, including the main process setup, renderer process entry point, and a simple React component.
Competitor Comparisons
A Foundation for Scalable Cross-Platform Apps
Pros of electron-react-boilerplate
- More mature and established project with a larger community
- Extensive documentation and examples
- Includes additional features like auto-updates and packaging scripts
Cons of electron-react-boilerplate
- Uses older build tools (webpack) which can be slower
- More complex setup and configuration
- Larger bundle size due to included features
Code Comparison
electron-react-boilerplate:
import { app, BrowserWindow, shell, ipcMain } from 'electron';
import { autoUpdater } from 'electron-updater';
import log from 'electron-log';
import MenuBuilder from './menu';
import { resolveHtmlPath } from './util';
electron-vite-react:
import { app, BrowserWindow, shell, ipcMain } from 'electron'
import { release } from 'node:os'
import { join } from 'node:path'
import { update } from './update'
The electron-react-boilerplate code includes more imports for additional features, while electron-vite-react has a more streamlined approach. The electron-vite-react project uses Vite as its build tool, which offers faster build times and a simpler configuration. It also has a smaller footprint and focuses on providing a minimal, modern setup for Electron and React development.
Both projects serve as excellent starting points for Electron and React applications, with electron-react-boilerplate offering more features out of the box, and electron-vite-react providing a leaner, more modern development experience.
Secure boilerplate for Electron app based on Vite. TypeScript + Vue/React/Angular/Svelte/Vanilla
Pros of vite-electron-builder
- More comprehensive out-of-the-box setup, including TypeScript, ESLint, and Prettier configurations
- Includes a pre-configured GitHub Actions workflow for automated builds and releases
- Supports hot module replacement (HMR) for both main and renderer processes
Cons of vite-electron-builder
- Slightly more complex project structure, which may be overwhelming for beginners
- Less frequently updated compared to electron-vite-react
- Requires more initial configuration and setup time
Code Comparison
electron-vite-react:
import { app, BrowserWindow } from 'electron'
import path from 'node:path'
const createWindow = () => {
const win = new BrowserWindow({
// ... window configuration
})
}
vite-electron-builder:
import { app, BrowserWindow } from 'electron'
import { join } from 'path'
import { URL } from 'url'
async function createWindow() {
const browserWindow = new BrowserWindow({
// ... window configuration
})
}
Both projects use similar approaches for creating the main window, but vite-electron-builder uses TypeScript and includes additional imports for path and URL handling.
Easily Build Your Vue.js App For Desktop With Electron
Pros of vue-cli-plugin-electron-builder
- Seamless integration with Vue CLI, providing a familiar development environment for Vue developers
- Extensive documentation and community support, making it easier for beginners to get started
- Built-in support for TypeScript and various build configurations
Cons of vue-cli-plugin-electron-builder
- Slower build times compared to electron-vite-react, especially for larger projects
- Less flexibility in customizing the build process, as it's more tightly coupled with Vue CLI
- Potentially larger bundle sizes due to the inclusion of Vue CLI dependencies
Code Comparison
vue-cli-plugin-electron-builder:
module.exports = {
pluginOptions: {
electronBuilder: {
builderOptions: {
// Configure electron-builder options here
}
}
}
}
electron-vite-react:
import { defineConfig } from 'vite'
import electron from 'vite-plugin-electron'
export default defineConfig({
plugins: [electron()]
})
The code comparison shows that vue-cli-plugin-electron-builder uses a Vue CLI configuration file, while electron-vite-react uses Vite's configuration system. This reflects the different build tools and ecosystems each project is based on.
electron-vite-react offers a more streamlined configuration process, leveraging Vite's simplicity and performance benefits. In contrast, vue-cli-plugin-electron-builder provides a more comprehensive set of options within the Vue CLI ecosystem, which may be preferable for developers already familiar with Vue CLI projects.
Clone to try a simple Electron app
Pros of minimal-repro
- Simpler setup, ideal for quick issue reproduction
- Lightweight, with minimal dependencies
- Easier to understand for beginners due to its bare-bones structure
Cons of minimal-repro
- Lacks advanced development features and optimizations
- Requires more manual configuration for complex projects
- No built-in support for modern web technologies like React
Code Comparison
minimal-repro:
const { app, BrowserWindow } = require('electron')
function createWindow () {
const win = new BrowserWindow({ width: 800, height: 600 })
win.loadFile('index.html')
}
electron-vite-react:
import { app, BrowserWindow, shell, ipcMain } from 'electron'
import { release } from 'node:os'
import { join } from 'node:path'
const createWindow = () => {
const win = new BrowserWindow({
width: 920,
height: 840,
webPreferences: {
preload: join(__dirname, '../preload/index.js'),
sandbox: false
},
})
}
The minimal-repro code is more straightforward, focusing on the basic window creation. In contrast, electron-vite-react includes additional imports and configuration options, reflecting its more feature-rich environment. The electron-vite-react setup is geared towards a React-based project with Vite as the build tool, offering a more comprehensive development experience but with added complexity.
:electron: A complete tool for building and publishing Electron applications
Pros of Electron Forge
- More mature and widely adopted in the Electron ecosystem
- Offers a comprehensive set of tools for packaging, publishing, and automating Electron app development
- Provides better integration with native dependencies and system-level features
Cons of Electron Forge
- Steeper learning curve for developers new to Electron
- Less flexibility in customizing the build process compared to Vite-based solutions
- Slower build times, especially for larger projects
Code Comparison
Electron Forge (package.json):
{
"scripts": {
"start": "electron-forge start",
"package": "electron-forge package",
"make": "electron-forge make"
}
}
Electron Vite React (package.json):
{
"scripts": {
"dev": "vite",
"build": "vite build && electron-builder",
"preview": "vite preview"
}
}
The code comparison shows that Electron Forge uses its own CLI commands for starting, packaging, and building the app, while Electron Vite React leverages Vite's commands for development and preview, with electron-builder for the final build process. This highlights the more integrated approach of Electron Forge versus the modular, Vite-centric approach of Electron Vite React.
Build smaller, faster, and more secure desktop and mobile applications with a web frontend.
Pros of Tauri
- Smaller application size due to native system components
- Better performance and resource efficiency
- Cross-platform development with a single codebase
Cons of Tauri
- Less mature ecosystem compared to Electron
- Limited access to certain native APIs
- Steeper learning curve for developers new to Rust
Code Comparison
Tauri (main.rs):
#![cfg_attr(
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
)]
fn main() {
tauri::Builder::default()
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
Electron Vite React (main.ts):
import { app, BrowserWindow } from 'electron'
import path from 'node:path'
const createWindow = () => {
const win = new BrowserWindow({
webPreferences: {
preload: path.join(__dirname, 'preload.js')
}
})
win.loadFile('index.html')
}
app.whenReady().then(() => {
createWindow()
})
Both frameworks offer solutions for building desktop applications using web technologies, but Tauri focuses on using native system components and Rust for the backend, while Electron Vite React uses Electron with a React frontend and Vite as the build tool.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
electron-vite-react
English | ç®ä½ä¸æ
ð Overview
ð¦ Ready out of the box
ð¯ Based on the official template-react-ts, project structure will be familiar to you
ð± Easily extendable and customizable
ðª Supports Node.js API in the renderer process
ð© Supports C/C++ native addons
ð Debugger configuration included
ð¥ Easy to implement multiple windows
ð« Quick Setup
# clone the project
git clone https://github.com/electron-vite/electron-vite-react.git
# enter the project directory
cd electron-vite-react
# install dependency
npm install
# develop
npm run dev
ð Debug
ð Directory structure
Familiar React application structure, just with electron
folder on the top :wink:
Files in this folder will be separated from your React application and built into dist-electron
âââ electron Electron-related code
â âââ main Main-process source code
â âââ preload Preload-scripts source code
â
âââ release Generated after production build, contains executables
â âââ {version}
â âââ {os}-{os_arch} Contains unpacked application executable
â âââ {app_name}_{version}.{ext} Installer for the application
â
âââ public Static assets
âââ src Renderer source code, your React application
ð§ Additional features
- electron-updater ð see docs
- playwright
â FAQ
Top Related Projects
A Foundation for Scalable Cross-Platform Apps
Secure boilerplate for Electron app based on Vite. TypeScript + Vue/React/Angular/Svelte/Vanilla
Easily Build Your Vue.js App For Desktop With Electron
Clone to try a simple Electron app
:electron: A complete tool for building and publishing Electron applications
Build smaller, faster, and more secure desktop and mobile applications with a web frontend.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot