簡體   English   中英

在對資產進行預編譯以進行生產后,出現“開發中找不到導入文件或字體不可讀的文件:”的錯誤。

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM