繁体   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