This project combines Electron (for desktop capabilities), React (for UI components), and Vite (for tooling). Below is a detailed explanation of how it works:
Familiar React application structure, just with electron
folder on the top 😉
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
- Creates cross-platform desktop apps using web technologies
- Main Process: Node.js environment that manages app lifecycle (
electron/main/index.ts
) - Renderer Process: Chromium-based window displaying your web app (
src/
) - Preload Scripts: Bridge between main/renderer processes (
electron/preload/index.ts
)
- Component-based UI library similar to Svelte
- Components live in
src/
directory:
- Modern frontend build tool with fast HMR (Hot Module Replacement)
- Configurations:
vite.config.ts
- Build configurationtsconfig.json
- TypeScript settings
-
Main Process starts (
electron/main/index.ts
)app.whenReady().then(() => { createWindow() // Creates browser window })
-
Preload Script executes (
electron/preload/index.ts
)- Exposes Node.js APIs safely to renderer:
contextBridge.exposeInMainWorld('ipcRenderer', ipcRenderer)
-
Renderer Process loads (
dist/index.html
→src/main.tsx
)ReactDOM.createRoot(document.getElementById('root')).render(<App />)
- Similar to Svelte's component model:
App.tsx
contains main UI- Components in
src/components/
- State management via
useState
hook
npm run dev
triggers:- Vite dev server for renderer (HMR enabled)
- Electron main process in watch mode
- Production build (
npm run build
):- Outputs to
dist/
(renderer) anddist-electron/
(main/preload)
- Outputs to
Example from src/demos/ipc.ts
:
// Renderer → Main
window.ipcRenderer.send('message', 'Hello from React!')
// Main → Renderer
ipcMain.on('message', (event, msg) => {
event.reply('reply', 'Message received!')
})
-
Place in
public/
directory (e.g.,public/node.svg
) -
Reference directly in JSX:
<img src="./node.svg" />
npm install # Install dependencies
npm run dev # Start dev environment
npm run build # Create production build
electron/main/index.ts
- Main processelectron/preload/index.ts
- Preload scriptsrc/App.tsx
- Root componentsrc/main.tsx
- Renderer entry pointvite.config.ts
- Build configuration