[英]After precompiling assets for production, I get “File to import not found or unreadable: fonts.” error in development
我有一個Rails 4應用,在資產文件夾中有一個fonts目錄,還有一些常用的東西。 我對我的資產進行了預編譯以進行生產,但是現在當我嘗試在本地工作時,我得到了:
Sass::SyntaxError
File to import not found or unreadable: fonts.
整個錯誤如下所示:
找不到答案很幸運。 謝謝。
編輯
我嘗試將我的資產移動到gemfile的資產塊中,但沒有執行任何操作。 在此之前,他們沒有任何障礙,也沒有在那里工作。
application.rb中
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module Atbp
class Application < Rails::Application
config.assets.paths << Rails.root.join("app", "assets", "fonts")
end
end
在config/application.rb
,查看config.assets.paths
行。 它應該包含“字體”。
config.assets.paths << Rails.root.join("app", "assets", "fonts")
之后,您的字體應該可以在font-path
helper中使用:
@font-face
font-family: 'FontName'
src: url(font-path('font-name.eot'))
...
原來我試圖@import "fonts"
,它是目錄而不是文件。 因此,正如@nickcoxdotme建議的那樣,我添加了
config.assets.paths << Rails.root.join("app", "assets", "fonts")
到application.rb
另外,我在scss文件中調用字體是這樣的:
@font-face {
font-family: 'hamilton19';
src: asset_url('hamilton_wood_type_foundry_-_hwtunitgothic-719-webfont.eot');
src: asset_url('hamilton_wood_type_foundry_-_hwtunitgothic-719-webfont.eot?#iefix') format('embedded-opentype'),
asset_url(hamilton_wood_type_foundry_-_hwtunitgothic-719-webfont.woff') format('woff'),
asset_url('hamilton_wood_type_foundry_-_hwtunitgothic-719-webfont.ttf') format('truetype'),
asset_url('hamilton_wood_type_foundry_-_hwtunitgothic-719-webfont.svg#MonoSocialIconsFont') format('svg');
src: asset_url('hamilton_wood_type_foundry_-_hwtunitgothic-719-webfont.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
當我需要在路徑中使用font_url
和'/assets/
來調用它們時。
@font-face {
font-family: 'hamilton19';
src: font_url('/assets/hamilton_wood_type_foundry_-_hwtunitgothic-719-webfont.eot');
src: font_url('/assets/hamilton_wood_type_foundry_-_hwtunitgothic-719-webfont.eot?#iefix') format('embedded-opentype'),
font_url('/assets/hamilton_wood_type_foundry_-_hwtunitgothic-719-webfont.woff') format('woff'),
font_url('/assets/hamilton_wood_type_foundry_-_hwtunitgothic-719-webfont.ttf') format('truetype'),
font_url('/assets/hamilton_wood_type_foundry_-_hwtunitgothic-719-webfont.svg#MonoSocialIconsFont') format('svg');
src: font_url('/assets/hamilton_wood_type_foundry_-_hwtunitgothic-719-webfont.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.