2021-11-11 08:17:54 +08:00
# vite-react-electron
2021-11-10 21:03:59 +08:00
2022-06-10 09:16:43 +08:00
[](https://github.com/vitejs/awesome-vite)
2022-08-16 08:13:07 +08:00



[](https://nodejs.org/about/releases)
2021-11-10 21:03:59 +08:00
2022-06-10 09:16:43 +08:00
[English ](README.md ) | 简体中文
2021-11-10 21:03:59 +08:00
2021-12-18 10:23:56 +08:00
## 概述
2022-06-10 09:16:43 +08:00
📦 开箱即用
2022-08-03 08:19:59 +08:00
🎯 基于官方的 [template-react-ts ](https://github.com/vitejs/vite/tree/main/packages/create-vite/template-react-ts ), 低侵入性
2022-06-10 09:16:43 +08:00
🌱 结构清晰,可塑性强
2022-06-13 09:54:41 +08:00
💪 支持在渲染进程中使用 Electron、Node.js API
🔩 支持 C/C++ 模块
2022-06-10 09:16:43 +08:00
🖥 很容易实现多窗口
2021-12-18 10:23:56 +08:00
2022-04-25 08:51:42 +08:00
## 快速开始
2021-11-10 21:03:59 +08:00
2022-03-13 08:45:27 +08:00
```sh
2023-08-02 09:59:37 +08:00
# clone the project
git clone https://github.com/electron-vite/electron-vite-react.git
# enter the project directory
cd electron-vite-react
2021-11-10 21:03:59 +08:00
2023-08-02 09:59:37 +08:00
# install dependency
npm install
# develop
npm run dev
```
2022-04-25 08:51:42 +08:00
## 调试
2023-04-23 10:19:58 +08:00

2021-11-10 21:03:59 +08:00
## 目录
2022-12-22 11:31:38 +08:00
*🚨 默认情况下, `electron` 文件夹下的文件将会被构建到 `dist-electron` *
2021-12-29 09:33:21 +08:00
2021-11-10 21:03:59 +08:00
```tree
2022-12-22 11:31:38 +08:00
├── electron Electron 源码文件夹
│ ├── main Main-process 源码
│ └── preload Preload-scripts 源码
2022-06-28 10:43:17 +08:00
│
2022-12-22 11:31:38 +08:00
├── release 构建后生成程序目录
2022-07-11 08:43:06 +08:00
│ └── {version}
2022-12-22 11:31:38 +08:00
│ ├── {os}-{os_arch} 未打包的程序(绿色运行版)
│ └── {app_name}_{version}.{ext} 应用安装文件
2022-06-28 10:43:17 +08:00
│
2022-12-22 11:31:38 +08:00
├── public 同 Vite 模板的 public
└── src 渲染进程源码、React代码
2021-11-12 09:01:59 +08:00
```
2023-04-17 10:48:37 +08:00
<!--
2022-07-20 19:07:54 +08:00
## 🚨 这需要留神
2022-06-27 10:17:20 +08:00
2022-12-09 09:12:30 +08:00
默认情况下,该模板在渲染进程中集成了 Node.js, 如果你不需要它, 你只需要删除下面的选项. [因为它会修改 Vite 默认的配置 ](https://github.com/electron-vite/vite-plugin-electron-renderer#config-presets-opinionated ).
2022-06-28 10:41:23 +08:00
2022-07-20 08:57:24 +08:00
```diff
# vite.config.ts
2022-06-28 10:41:23 +08:00
2022-12-22 11:31:38 +08:00
export default {
plugins: [
...
- // Use Node.js API in the Renderer-process
- renderer({
- nodeIntegration: true,
- }),
...
],
}
2022-07-20 08:57:24 +08:00
```
2023-04-17 10:48:37 +08:00
-->
2022-06-28 10:41:23 +08:00
2023-03-15 09:20:30 +08:00
## 🔧 额外的功能
1. Electron 自动更新 👉 [阅读文档 ](src/components/update/README.zh-CN.md )
2. Playwright 测试
## ❔ FAQ
2022-01-21 17:22:02 +08:00
2022-11-19 08:36:32 +08:00
- [C/C++ addons, Node.js modules - Pre-Bundling ](https://github.com/electron-vite/vite-plugin-electron-renderer#dependency-pre-bundling )
2023-04-17 10:48:37 +08:00
- [dependencies vs devDependencies ](https://github.com/electron-vite/vite-plugin-electron-renderer#dependencies-vs-devdependencies )
2022-11-19 08:36:32 +08:00
## 🍵 🍰 🍣 🍟
< img width = "270" src = "https://github.com/caoxiemeihao/blog/blob/main/assets/$qrcode/$.png?raw=true" >