From c1e43c224ce16e9bbf06788cf0c36ef0566829ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8D=89=E9=9E=8B=E6=B2=A1=E5=8F=B7?= <308487730@qq.com> Date: Sun, 16 May 2021 20:28:02 +0800 Subject: [PATCH] chore: UPDATE --- README.md | 32 ++++++++++++++++++++++++++------ vite.config.ts | 2 +- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index d4f8784..def5da6 100644 --- a/README.md +++ b/README.md @@ -9,14 +9,34 @@ - npm run build ## Note -- Using `Nodejs` `Electron` API in vite and using require to import +- In the development environment, we need to transform the `Electron` related API into commonjs +- And you can only use ESM +- So far, I've written an `esm2cjs` plugin ```ts - // import { readFile } from 'fs' - // import { ipcRenderer } from 'electron' - - const { readFile } = require('fs') - const { ipcRenderer } = require('electron') + import { ipcRenderer } from 'electron' + import Store from 'electron-store' + // Will generate + const { ipcRenderer } = require("electron") + const Store = require("electron-store") ``` +- It works! + +- 🚀 + +- 开发模式下 Electron 相关的 API 需要转换成 commonjs +- 并且你只能用 ESM +- 为此我写了一个 `esm2cjs` 插件 + +## electron-vue-vite-webpack +- If you are afraid of stepping on the pit, you can consider using this project +[ https://github.com/caoxiemeihao/electron-vue-vite-webpack ]( https://github.com/caoxiemeihao/electron-vue-vite-webpack ) + The production environment is packaged with 'webpack' + +- 🚀 + +- 如果你怕踩坑,可以考虑用这个项目 + [https://github.com/caoxiemeihao/electron-vue-vite-webpack](https://github.com/caoxiemeihao/electron-vue-vite-webpack) + 生产环境使用 `webpack` 打包的 --- diff --git a/vite.config.ts b/vite.config.ts index 37fa13a..c5e653c 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -45,7 +45,7 @@ export default defineConfig(env => { optimizeDeps: { exclude: [ 'electron', - 'electron-store', // optional + // 'electron-store', // optional ], }, build: {