Electron-Q&A
electron踩坑排错
项目启动
项目框架,依赖及插件版本如下:
"vue": "^3.2.45"
"vite": "^4.0.0"
"electron": "^22.0.2"
"vite-plugin-electron": "^0.11.1"
项目首次运行
删除package.json文件中"type":"module"
,添加"main": "dist/index.js"
后
提示缺少入口文件,修改vite.config.ts
1 | /* |
vite项目启动成功,electron仍然提示缺少入口文件
我们的文件中配置的
修改package.json中"main": "dist-electron/index.js"
后
启动成功!
项目打包
打包安装后应用内白屏,加载打包后文件失败
1 | // 加载文件路径 |
应该加载项目打包后dist文件夹下的index.html,修改electron下的index.ts中加载文件的路径
1 | /* |
重新打包安装后,仍然加载不到文件
vite-plugin-electron ^0.11.1版本
将打包后的入口文件输出在dist-electron
路径下,尝试修改插件的文件输出路径,将打包后的入口文件输出在dist/electron
路径下,同步修改package.json中入口文件路径"main": "dist/electron/index.js"
,重新打包
1 | ⨯ Application entry file "dist/electron/index.js" in the "/Users/xiuji/Desktop/workplace/own/electron-demo/release/mac/electron-demo.app/Contents/Resources/app.asar" does not exist. Seems like a wrong configuration. failedTask=build stackTrace=Error: Application entry file "dist/electron/index.js" in the "/Users/xiuji/Desktop/workplace/own/electron-demo/release/mac/electron-demo.app/Contents/Resources/app.asar" does not exist. Seems like a wrong configuration. |
修改package.json中打包配置项
1 | { |
修改electron/index.ts
1 | /* |
重新安装运行
资源加载成功,白屏解决!
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Xiuji957!