简体   繁体   English

在对资产进行预编译以进行生产后,出现“开发中找不到导入文件或字体不可读的文件:”的错误。

[英]After precompiling assets for production, I get “File to import not found or unreadable: fonts.” error in development

I have a Rails 4 app with a fonts directory in the assets folder, along with the usual stuff. 我有一个Rails 4应用,在资产文件夹中有一个fonts目录,还有一些常用的东西。 I precompiled my assets for production, but now when I try to work locally I get: 我对我的资产进行了预编译以进行生产,但是现在当我尝试在本地工作时,我得到了:

Sass::SyntaxError
File to import not found or unreadable: fonts.

The whole error looks like this: 整个错误如下所示:

在此处输入图片说明

Haven't had much luck finding an answer. 找不到答案很幸运。 Thanks. 谢谢。

EDIT 编辑

I tried moving my assets into the assets block in the gemfile but that did nothing. 我尝试将我的资产移动到gemfile的资产块中,但没有执行任何操作。 Before that they weren't in any block, didn't work there either. 在此之前,他们没有任何障碍,也没有在那里工作。

application.rb 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

In your config/application.rb , look at your config.assets.paths line. config/application.rb ,查看config.assets.paths行。 It should include 'fonts'. 它应该包含“字体”。

config.assets.paths << Rails.root.join("app", "assets", "fonts")

Edit 编辑

After that, your fonts should be available with the font-path helper: 之后,您的字体应该可以在font-path helper中使用:

@font-face
  font-family: 'FontName'
  src: url(font-path('font-name.eot'))
  ...

Turns out I was trying to @import "fonts" , which is a directory and not a file. 原来我试图@import "fonts" ,它是目录而不是文件。 So as @nickcoxdotme suggested, I added 因此,正如@nickcoxdotme建议的那样,我添加了

config.assets.paths << Rails.root.join("app", "assets", "fonts")

to application.rb application.rb

In addition, I was calling my fonts in the scss file like so: 另外,我在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;
}

When I needed to be calling them with font_url and '/assets/ in the path. 当我需要在路径中使用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.

相关问题 找不到导入文件或文件不可读:生产模式中的指南针 - File to import not found or unreadable: compass in production mode 错误:要导入的文件未找到或不可读:mycustom.scss。 running:rake assets:precompile - Error: File to import not found or unreadable: mycustom.scss. running: rake assets:precompile 投产时错误预编译资产 - error precompiling assets when moving to production Sass::SyntaxError:未找到要导入的文件或无法读取:生产中的指南针 - Sass::SyntaxError: File to import not found or unreadable: compass in production 找不到导入文件或文件不可读:引导程序错误行#5 - File to import not found or unreadable: bootstrap error line #5 Rails资产未在生产中进行预编译 - Rails assets not precompiling in production Rails 3应用程序中的Sass导入错误 - “导入未找到或不可读的文件:指南针” - Sass import error in Rails 3 app - “File to import not found or unreadable: compass” bootstrap:要导入的文件未找到或不可读 - bootstrap :File to import not found or unreadable 要导入的文件未找到或不可读:bootstrap - File to import not found or unreadable: bootstrap 要导入的Sass文件未找到或不可读 - Sass File to import not found or unreadable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM