[英]Rails: Bower CSS can't load its fonts
我下載了 Metro UI 和下載到這個文件夾中的 CSS:
/vendor/assets/bower_components/metro-bootstrap/dist/css/metro-bootstrap.css
然后我包含了來自app/assets/stylesheets/application.css.scss
的 CSS,如下所示:
/*
* require bootstrap-sass
*= require_tree .
*= require_self
require metro-bootstrap (not sure if I should include this?)
*/
@import "metro-bootstrap/dist/css/metro-bootstrap.css";
它拋出一個錯誤,因為 CSS 正在嘗試加載這樣的字體:
@font-face {
font-family: 'Glyphicons Halflings';
src: url('../fonts/glyphicons-halflings-regular.eot');
src: url('../fonts/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'), url('../fonts/glyphicons-halflings-regular.woff') format('woff'), url('../fonts/glyphicons-halflings-regular.ttf') format('truetype'), url('../fonts/glyphicons-halflings-regular.svg#glyphicons_halflingsregular') format('svg');
}
字體位於此文件夾中:
/vendor/assets/bower_components/metro-bootstrap/dist/fonts/
但是這個文件夾不是 Ruby 自然訪問的,因為 Ruby 有點編譯新文件夾中的所有資產和東西(我不太清楚)
你能幫我解決這個問題嗎? 我希望它以正確的路徑鏈接到字體,而不必修改 CSS,或者將 CSS 復制到我的資產文件夾,否則它會破壞使用 Bower 安裝依賴項的目的。
我能夠使用相同的 Metro 主題設置演示應用程序(實際上就像字體一樣,所以感謝您的分享)。 讓我向您介紹我是如何設置的,看看它是否適合您,或者您是否錯過了一步。
首先,我創建了一個.bowerrc文件(也許將您的文件更改為 bower_components 作為目錄路徑?):
{
"directory": "vendor/assets/components"
}
然后bower init
創建 json 文件。
然后bower install metro-bootstrap
應用程序.css.scss
*
*= require_tree .
*= require_self
*/
@import "metro-bootstrap/dist/css/metro-bootstrap.css";
然后我啟動了我的服務器並呈現了正確的字體。 這是在 Rails 應用程序中設置 Bower 的一個很好的資源(沒有 gem): http : //dotwell.io/taking-advantage-of-bower-in-your-rails-4-app/ 。 希望這能給你一些想法或幫助你。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.