electron-vite-react/README.md

92 lines
3.3 KiB
Markdown
Raw Normal View History

2022-06-07 02:24:14 +08:00
# electron-vite-react
2021-11-06 22:27:23 +08:00
2022-06-10 09:16:43 +08:00
[![awesome-vite](https://awesome.re/mentioned-badge.svg)](https://github.com/vitejs/awesome-vite)
2022-08-16 08:13:07 +08:00
![GitHub stars](https://img.shields.io/github/stars/caoxiemeihao/vite-react-electron?color=fa6470)
![GitHub issues](https://img.shields.io/github/issues/caoxiemeihao/vite-react-electron?color=d8b22d)
![GitHub license](https://img.shields.io/github/license/caoxiemeihao/vite-react-electron)
[![Required Node.JS >= 14.18.0 || >=16.0.0](https://img.shields.io/static/v1?label=node&message=14.18.0%20||%20%3E=16.0.0&logo=node.js&color=3f893e)](https://nodejs.org/about/releases)
2021-11-06 22:27:23 +08:00
2022-06-10 09:16:43 +08:00
English | [简体中文](README.zh-CN.md)
2021-12-18 10:23:56 +08:00
## 👀 Overview
2021-12-18 10:23:56 +08:00
📦 Ready out of the box
2022-08-03 08:19:29 +08:00
🎯 Based on the official [template-react-ts](https://github.com/vitejs/vite/tree/main/packages/create-vite/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
2022-07-21 09:15:42 +08:00
🐞 Debugger configuration included
🖥 Easy to implement multiple windows
2021-12-18 10:23:56 +08:00
2023-08-02 09:59:37 +08:00
## 🛫 Quick Setup
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
2022-03-13 08:45:27 +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
2022-07-21 09:15:42 +08:00
## 🐞 Debug
2022-04-25 08:51:42 +08:00
2023-04-23 10:19:58 +08:00
![electron-vite-react-debug.gif](/electron-vite-react-debug.gif)
2022-03-13 08:45:27 +08:00
## 📂 Directory structure
2021-11-10 21:19:02 +08:00
Familiar React application structure, just with `electron` folder on the top :wink:
2022-12-22 11:31:38 +08:00
*Files in this folder will be separated from your React application and built into `dist-electron`*
2021-12-29 09:33:21 +08:00
2021-11-10 21:19:02 +08:00
```tree
2022-12-22 11:31:38 +08:00
├── electron Electron-related code
│ ├── main Main-process source code
│ └── preload Preload-scripts source code
2022-06-27 10:15:29 +08:00
2022-12-22 11:31:38 +08:00
├── release Generated after production build, contains executables
2022-07-11 08:43:06 +08:00
│ └── {version}
2022-12-22 11:31:38 +08:00
│ ├── {os}-{os_arch} Contains unpacked application executable
│ └── {app_name}_{version}.{ext} Installer for the application
2022-06-27 10:15:29 +08:00
2022-12-22 11:31:38 +08:00
├── public Static assets
└── src Renderer source code, your React application
2021-11-10 21:19:02 +08:00
```
2023-04-17 10:48:37 +08:00
<!--
2022-07-20 19:16:34 +08:00
## 🚨 Be aware
2022-01-31 12:49:04 +08:00
2022-07-21 17:19:33 +08:00
This template integrates Node.js API to the renderer process by default. If you want to follow **Electron Security Concerns** you might want to disable this feature. You will have to expose needed API by yourself.
2022-12-09 09:12:30 +08:00
To get started, remove the option as shown below. This will [modify the Vite configuration and disable this feature](https://github.com/electron-vite/vite-plugin-electron-renderer#config-presets-opinionated).
2022-06-27 10:15:29 +08:00
2022-07-20 08:57:24 +08:00
```diff
# vite.config.ts
2022-10-19 19:11:36 +08:00
export default {
plugins: [
2022-12-22 11:31:38 +08:00
...
2022-10-19 19:11:36 +08:00
- // Use Node.js API in the Renderer-process
- renderer({
- nodeIntegration: true,
- }),
2022-12-22 11:31:38 +08:00
...
2022-10-19 19:11:36 +08:00
],
}
2022-07-20 08:57:24 +08:00
```
2023-04-17 10:48:37 +08:00
-->
2022-01-31 12:49:04 +08:00
## 🔧 Additional features
1. electron-updater 👉 [see docs](src/components/update/README.md)
1. playwright
## ❔ FAQ
2022-01-31 12:49:04 +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)