过时文章提醒:
提醒大家直接使用 electron 22.x.y + 以上版本,这样能对应上最新的 Electron 文档,否则很多功能在老版中是不存在,新版对于 utility-process 和 MessageChannelMain
- utility-process 可以做一些小逻辑,例如一些网络检测服务,定时器服务,调度服务,没有必要用 renderer 来搞;Electron 工具进程utilityProcess 使用中遇到的坑点解决方案_森叶的博客-CSDN博客
- MessageChannelMain 在多窗口通信时非常方便,不需要主进程作为中转站,大大节约了开发时间,异步控制链路变得更简单Electron 多端通信桥 MessageChannelMain和 MessagePortMain 坑点汇集_森叶的博客-CSDN博客
-
安装流程没有问题
# 安装 vue-cli 和 脚手架样板代码
npm install -g vue-cli
vue init simulatedgreg/electron-vue my-project
# 安装依赖并运行你的程序
cd my-project
yarn # 或者 npm install
yarn run dev # 或者 npm run dev
-
M1 必须是 electron 11 版本才能用,所以 package 要改为 electron 11+,这里选择的是 13
"electron": "^13.2.1"
-
其次在实例化代码的时候,sass 不要选择,测试都不要选择,不然会莫名其妙的要下载 Chromedriver1.0.8,且每次装库都要很久,即使用了淘宝镜像,也没太快
-
装完之后,因为用了 electron 13,导致需要重新配置一些参数
mainWindow = new BrowserWindow({
height: 563,
useContentSize: true,
width: 1000,
webPreferences: {
enableRemoteModule: true,
devTools: true,
contextIsolation: false,
nodeIntegration: true,
nodeIntegrationInWorker: true
}
})
-
vue 的 webpack 热更新总是报 404 错误,在 github 有人说是这里注释掉了,放开就不报错,找不到时就全局搜下
1. windows 至少使用electron 8.2.0 否则,报一个Uncaught TypeError: Object.fromEntries is not a function,这是electron 2的浏览器内核太低导致,升级到8即可,之所以不升级到8.2以上,是因为9以上,装插件会报browser_action错误,目前还没找到好的解决方案
2. 安装插件报以下错误
Unrecognized manifest key 'browser_action'. Unrecognized manifest key 'minimum_chrome_version'. Unrecognized manifest key 'update_url'. Manifest contains a differential_fingerprint key that will be overridden on extension update. Cannot load extension with file or directory name _metadata. Filenames starting with "_" are reserved for use by the system.
处理方式,增加 { allowFileAccess: true }
await session.defaultSession.loadExtension(vueDevToolsPath, { allowFileAccess: true })