# electron-vite

node vite

English | [简体中文](./README.zh-CN.md) > An Electron CLI integrated with Vite --- ## Features - ⚡️Use the same way as [Vite](https://vitejs.dev) - 🔨Main process, renderer process and preload script source code are built using Vite - 📃Main process, renderer process and preload script Vite configuration combined into one file - 📦Preset optimal build configuration - 🚀HMR for renderer processes ## Usage ### Install ```sh npm i electron-vite -D ``` ### Development & Build In a project where `electron-vite` is installed, you can use `electron-vite` binary directly with `npx electron-vite` or add the npm scripts to your `package.json` file like this: ```json { "scripts": { "start": "electron-vite preview", // start electron app to preview production build "dev": "electron-vite dev", // start dev server and electron app "prebuild": "electron-vite build" // build for production } } ``` In order to use the renderer process HMR, you need to use the `environment variables` to determine whether the window browser loads a local html file or a remote URL. ```js function createWindow() { // Create the browser window const mainWindow = new BrowserWindow({ width: 800, height: 600, webPreferences: { preload: path.join(__dirname, '../preload/index.js') } }) // Load the remote URL for development or the local html file for production if (!app.isPackaged && process.env['ELECTRON_RENDERER_URL']) { mainWindow.loadURL(process.env['ELECTRON_RENDERER_URL']) } else { mainWindow.loadFile(path.join(__dirname, '../renderer/index.html')) } } ``` **Note**: For development, the renderer process `index.html` file needs to reference your script code via `