2020-08-16 12:49:24 +08:00
|
|
|
|
# electron-vue-vite
|
2021-03-30 09:57:22 +08:00
|
|
|
|
`Electron` + `Vue3` + `Vite2` integration
|
2020-08-16 20:42:52 +08:00
|
|
|
|
|
|
|
|
|
## How and Why
|
2021-03-30 09:57:22 +08:00
|
|
|
|
- `Vite` is the scaffold of the future
|
2020-08-16 21:00:37 +08:00
|
|
|
|
|
2020-10-05 21:48:49 +08:00
|
|
|
|
## Command
|
2020-08-17 09:21:07 +08:00
|
|
|
|
- npm run dev
|
|
|
|
|
- npm run build
|
2020-08-16 21:00:37 +08:00
|
|
|
|
|
2021-03-30 09:57:22 +08:00
|
|
|
|
## Note
|
2021-05-16 20:28:02 +08:00
|
|
|
|
- In the development environment, we need to transform the `Electron` related API into commonjs
|
|
|
|
|
- And you can only use ESM
|
2021-05-23 11:13:49 +08:00
|
|
|
|
- So far, I've written an [vitejs-plugin-electron](https://github.com/caoxiemeihao/vitejs-plugins/tree/main/electron) plugin
|
2021-03-30 09:57:22 +08:00
|
|
|
|
```ts
|
2021-05-16 20:28:02 +08:00
|
|
|
|
import { ipcRenderer } from 'electron'
|
|
|
|
|
import Store from 'electron-store'
|
|
|
|
|
// Will generate
|
|
|
|
|
const { ipcRenderer } = require("electron")
|
|
|
|
|
const Store = require("electron-store")
|
2021-02-18 16:26:59 +08:00
|
|
|
|
```
|
2021-05-16 20:28:02 +08:00
|
|
|
|
- It works!
|
|
|
|
|
|
|
|
|
|
- 🚀
|
|
|
|
|
|
|
|
|
|
- 开发模式下 Electron 相关的 API 需要转换成 commonjs
|
|
|
|
|
- 并且你只能用 ESM
|
2021-05-23 11:13:49 +08:00
|
|
|
|
- 为此我写了一个 [vitejs-plugin-electron](https://github.com/caoxiemeihao/vitejs-plugins/tree/main/electron) 插件
|
2021-05-16 20:28:02 +08:00
|
|
|
|
|
|
|
|
|
## electron-vue-vite-webpack
|
2021-05-23 14:48:11 +08:00
|
|
|
|
- If you're worried, you can consider using this project
|
2021-05-16 20:34:32 +08:00
|
|
|
|
[ https://github.com/caoxiemeihao/electron-vue-vite-webpack ]( https://github.com/caoxiemeihao/electron-vue-vite-webpack)
|
2021-05-16 20:28:02 +08:00
|
|
|
|
The production environment is packaged with 'webpack'
|
|
|
|
|
|
|
|
|
|
- 🚀
|
|
|
|
|
|
|
|
|
|
- 如果你怕踩坑,可以考虑用这个项目
|
|
|
|
|
[https://github.com/caoxiemeihao/electron-vue-vite-webpack](https://github.com/caoxiemeihao/electron-vue-vite-webpack)
|
2021-05-16 20:34:32 +08:00
|
|
|
|
生产环境使用 `webpack` 打包的
|
2020-09-02 09:19:15 +08:00
|
|
|
|
|
2020-08-17 09:21:07 +08:00
|
|
|
|
---
|
2020-08-16 21:00:37 +08:00
|
|
|
|
|
2021-03-30 09:57:22 +08:00
|
|
|
|

|
2021-05-08 17:29:38 +08:00
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## License
|
|
|
|
|
|
|
|
|
|
[MIT License](https://opensource.org/licenses/MIT)
|