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
[](https://github.com/vitejs/awesome-vite)
2021-11-11 08:17:54 +08:00



2021-11-07 18:10:55 +08:00
[](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
2022-06-10 09:16:43 +08:00
📦 Out of the box
2022-06-29 16:08:04 +08:00
🎯 Based on the official [react-ts ](https://github.com/vitejs/vite/tree/main/packages/create-vite/template-react-ts ) template, less invasive
2022-06-10 09:16:43 +08:00
🌱 Simple directory structure, real flexible
2022-06-29 07:40:54 +08:00
💪 Support Use Electron、Node.js API and in Electron-Renderer
2022-06-13 09:54:41 +08:00
🔩 Support C/C++ native addons
2022-06-10 09:16:43 +08:00
🖥 It's easy to implement multiple windows
2021-12-18 10:23:56 +08:00
2022-04-25 08:51:42 +08:00
## Quick start
2022-03-13 08:45:27 +08:00
```sh
npm create electron-vite
```
2022-06-07 07:22:07 +08:00

2022-04-25 08:51:42 +08:00
## Debug
2022-06-07 07:22:07 +08:00

2022-03-13 08:45:27 +08:00
2022-02-01 21:02:13 +08:00
## Directory structure
2021-11-10 21:19:02 +08:00
2022-06-10 09:16:43 +08:00
*🚨 By default, the files in `electron` folder will be built into the `dist/electron` *
2021-12-29 09:33:21 +08:00
2021-11-10 21:19:02 +08:00
```tree
2022-06-07 02:24:14 +08:00
├── electron Electron-related code
2022-06-27 10:15:29 +08:00
│ ├── main Main-process source code
│ ├── preload Preload-script source code
│ └── resources Resources for the production build
│ ├── icon.icns Icon for the application on macOS
│ ├── icon.ico Icon for the application
│ ├── installerIcon.ico Icon for the application installer
│ └── uninstallerIcon.ico Icon for the application uninstaller
│
2022-02-01 21:02:13 +08:00
├── release Generated after production build, contains executables
2022-06-27 10:15:29 +08:00
│ └──{version}
│ ├── {os}-unpacked Contains unpacked application executable
│ └── Setup.{ext} Installer for the application
│
2022-06-07 02:24:14 +08:00
├── public Static assets
└── src Renderer source code, your React application
2021-11-10 21:19:02 +08:00
```
2022-06-28 10:41:23 +08:00
## 🚨 `dependencies` vs `devDependencies`
2022-01-31 12:49:04 +08:00
2022-06-28 10:41:23 +08:00
**Put Node.js packages in `dependencies` **
2022-06-27 10:15:29 +08:00
2022-07-04 09:17:05 +08:00
**e.g.** `electron-store` `sqlite3` `serilaport` `mongodb` ...others
2022-06-28 10:41:23 +08:00
**Put Web packages in `devDependencies` **
2022-07-04 09:17:05 +08:00
**e.g.** `react` `react-dom` `react-router` `mobx` `zustand` `antd` `axios` ...others
2022-06-28 10:41:23 +08:00
2022-07-04 09:17:05 +08:00
See more 👉 [dependencies vs devDependencies ](https://github.com/electron-vite/vite-plugin-electron-renderer#dependencies-vs-devdependencies )
2022-06-28 10:41:23 +08:00
2022-07-04 09:17:05 +08:00
## 🚨 ESM packages
2022-06-28 10:41:23 +08:00
2022-07-04 09:17:05 +08:00
**e.g.** `node-fetch` `execa` `got` ...others
2022-06-28 10:41:23 +08:00
2022-07-04 09:17:05 +08:00
1. `npm i vite-plugin-esmodule -D`
2. Configure in vite.config.ts
```ts
import esmodule from 'vite-plugin-esmodule'
export default {
plugins: [
esmodule(['got', 'execa', 'node-fetch']),
],
}
```
2022-06-27 10:15:29 +08:00
<!--
2022-02-05 08:01:45 +08:00
- First, you need to know if your dependencies are needed after the application is packaged.
2022-01-31 12:49:04 +08:00
2022-02-05 08:01:45 +08:00
- Like [serialport ](https://www.npmjs.com/package/serialport ), [sqlite3 ](https://www.npmjs.com/package/sqlite3 ) they are node-native modules and should be placed in `dependencies` . In addition, Vite will not build them, but treat them as external modules.
2022-01-31 12:49:04 +08:00
2022-02-05 08:01:45 +08:00
- Dependencies like [Vue ](https://www.npmjs.com/package/vue ) and [React ](https://www.npmjs.com/package/react ), which are pure javascript modules that can be built with Vite, can be placed in `devDependencies` . This reduces the size of the application.
2022-06-27 10:15:29 +08:00
-->