fix: 修复 electron-vite 环境下 process.env.VITE_DEV_SERVER_URL 获取失败导致的启动白屏问题#7
Open
aidanHu wants to merge 2 commits intoMemeCalculate:mainfrom
Open
fix: 修复 electron-vite 环境下 process.env.VITE_DEV_SERVER_URL 获取失败导致的启动白屏问题#7aidanHu wants to merge 2 commits intoMemeCalculate:mainfrom
aidanHu wants to merge 2 commits intoMemeCalculate:mainfrom
Conversation
Author
|
主要是在mac中运行的时候提示这个错误 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题描述
在运行
npm run dev时,由于前端使用了electron-vite构建工具,开发服务器启动时注入的环境变量是ELECTRON_RENDERER_URL,而不是原有的VITE_DEV_SERVER_URL。这导致main.ts无法正确获取开发服务器的本地 URL,错误进入了查找本地打包后index.html的逻辑,最终引发ERR_FILE_NOT_FOUND的白屏报错。修复内容
修改了
electron/main.ts中的环境变量获取语句,增加了对ELECTRON_RENDERER_URL的兼容支持:export const VITE_DEV_SERVER_URL = process.env['ELECTRON_RENDERER_URL'] || process.env['VITE_DEV_SERVER_URL']该修复已在本地通过测试,执行
npm run dev后可以正常渲染页面。