問題描述
我已經使用 npm 下載了 FontAwesome,然后使用 grunts 復制任務將 css 文件和字體復制到我的電子應用程序根目錄中的正確文件夾中.
I have downloaded FontAwesome using npm and then copied the css-file and the fonts into the right folders in the root-diretory of my electron-application using grunts copy task.
到目前為止一切順利.一切都在它應該在的地方.
So far so good. Everything is where it is supposed to be.
現在,當我在我的應用程序中引用 FontAwesome 時,圖標不會被加載.這些是我在控制臺中遇到的錯誤:
Now, when i am referencing FontAwesome in my app, the icons do not get loaded. These are the errors that I get in the console:
解碼下載的字體失敗:
file:///path/to/fonts/fontawesome-webfont.woff2?v=4.4.0
OTS 解析錯誤:無法將 WOFF 2.0 字體轉換為 SFNT
Failed to decode downloaded font:
file:///path/to/fonts/fontawesome-webfont.woff2?v=4.4.0
OTS parsing error: Failed to convert WOFF 2.0 font to SFNT
解碼下載的字體失敗:
file:////path/to/fonts/fontawesome-webfont.woff?v=4.4.0
OTS 解析錯誤:WOFF 標頭中的文件大小不正確
Failed to decode downloaded font:
file:////path/to/fonts/fontawesome-webfont.woff?v=4.4.0
OTS parsing error: incorrect file size in WOFF header
解碼下載的字體失敗:
file:////path/to/fonts/fontawesome-webfont.ttf?v=4.4.0
OTS解析錯誤:表目錄的entrySelector不正確
Failed to decode downloaded font:
file:////path/to/fonts/fontawesome-webfont.ttf?v=4.4.0
OTS parsing error: incorrect entrySelector for table directory
我已經嘗試通過刪除所有版本參數來修改 FontAwesome 的 css 文件,但這似乎不是問題.通過 electron .
啟動應用程序以及在瀏覽器中查看 html 文件時都會出現問題.
I have already tried to modify FontAwesome's css file by removing all the version parameters but this does not seem to be the problem. The Issues comes up both by starting the app via electron .
and when viewing the html-file in the browser.
更新
回答一些評論:
- 此問題出現在電子和瀏覽器中(在 chrome 和 firefox 中測試)
- 我使用的是最新版本的 FontAwesome (4.4.0) 和 Electron (0.32.1)(通過 npm 全新安裝)
- css 的加載方式如下:
推薦答案
問題出在我的 grunt 文件中.我試圖通過簡單地在他們的供應商網站上手動下載所有依賴項并將它們放在我項目的相應腳本文件夾中來重現該問題 - 突然它起作用了.
The Problem was in my grunt-file. I tried to reproduce the issue by simply downloading all dependencies manually at their vendors websites and placed them in the corresponding script-folder of my project - suddenly it worked.
我現在切換到 gulp,它仍然有效.不知道我在 grunt 上做錯了什么......
I switched to gulp now and it still works. No idea what i was doing wrong with grunt though...
這篇關于FontAwesome 無法在本地和電子應用程序中加載字體的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!