umbrella22 / electron-vite-template

This project is a vue3 + Vite + electron project template composed of Vite and rollup. It has the same functions as my previous electron+Vue+template project
Other
398 stars 108 forks source link

打包后字体图标不生效问题 #130

Closed a-cool-boy closed 5 months ago

a-cool-boy commented 5 months ago

运行字体图标正常显示,打包后字体图标不生效了,可能是文件路径问题?但我对electron还不是很熟悉,特来求助,望不吝赐教!

mlmdflr commented 5 months ago

百分之八十是路径问题,但还是请你贴图代码或者建一个示例的demo仓库放上来

a-cool-boy commented 5 months ago

百分之八十是路径问题,但还是请你贴图代码或者建一个示例的demo仓库放上来 你好 以下是字体图标使用相关代码 /iconfont目录是字体图标相关文件 // 页面中使用

a-cool-boy commented 5 months ago

百分之八十是路径问题,但还是请你贴图代码或者建一个示例的demo仓库放上来 码云demo: https://gitee.com/qianmo_xx/electron-test.git

mlmdflr commented 5 months ago

百分之八十是路径问题,但还是请你贴图代码或者建一个示例的demo仓库放上来 你好 以下是字体图标使用相关代码 /iconfont目录是字体图标相关文件 // 页面中使用

很显然是路径问题,这个不是electron的问题,是vite的基础问题 image 你这个图标的代码放在assets路径下是不会被打包进来的

解决: 你只需要将需要的图标代码按照一个个文件夹的方式统一放在public路径下,在这样如图这样设置路径即可 image 通过import.meta.url就可以解决生产开发环境路径不一致的问题

效果: image

参考: vite文档 https://cn.vitejs.dev/guide/assets.html#the-public-directory 没事多看看

mlmdflr commented 5 months ago

百分之八十是路径问题,但还是请你贴图代码或者建一个示例的demo仓库放上来 码云demo: https://gitee.com/qianmo_xx/electron-test.git

我的代码暂存在奶牛上 这个是下载链接 https://cowtransfer.com/s/3098687ed59743 这个是口令 aztiy6

七天后失效请尽快下载

a-cool-boy commented 5 months ago

@mlmdflr 多谢