Heroku字体资产不起作用 [英] Heroku font assets not working

查看:96
本文介绍了Heroku字体资产不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

app / assets / fonts

中放置字体

新增

 添加字体路径
config.assets.paths<< Rails.root.join('app','assets','fonts')

预编译附加资产
config.assets.precompile + =%w(.svg .eot .woff。 ttf)

在production.rb和development.rb中

在css中链接的字体类似于:

  @ font-face {
font-family:'Icomoon' ;
src:url('/ assets / icomoon.eot'); ('/ assets / icomoon.svg#icomoon')格式('svg') '),
url('/ assets / icomoon.woff')格式('woff'),
url('/ assets / icomoon.ttf')格式('truetype');
font-weight:normal;
font-style:normal;
}

似乎可以在开发中使用。但在HEROKU似乎没有工作。它找不到/assets/icomoon.eot。

此链接中的解决方案似乎无效



在Rails资产管道中使用字体

解决方案

如果您使用普通的旧css来查找资产而不是资产管道帮助程序,则像字体这样的资产可用于开发,但不能用于生产。 Rails 4对资产管道添加了重大更改,以鼓励用户正确使用它,而不是使用引用资产的旧css方法。为了解决这个问题,您需要使用新的资产管道助手指向你的字体的指纹,缓存版本。您不需要 url (它不使用资产管道),您需要使用 font-url 它)。要做到这一点,您可能需要使用Sass或在样式表中嵌入ERB。



示例(使用SCSS):

  @ font-face {
font-family:'Icomoon';
src:font-url(/ assets / icomoon.eot); (/ assets / icomoon.svg#icomoon)格式(svg) ),font-url(/ assets / icomoon.woff)格式(woff),font-url(/ assets / icomoon.ttf)格式(truetype);
font-weight:normal;
font-style:normal;
}

请参阅: http://guides.rubyonrails.org/asset_pipeline.html#coding-links-to-assets


Placed fonts in app/assets/fonts

Added

Add the fonts path
config.assets.paths << Rails.root.join('app', 'assets', 'fonts')

Precompile additional assets
config.assets.precompile += %w( .svg .eot .woff .ttf )

in production.rb and development.rb

Fonts linked in css like:

@font-face {
  font-family: 'Icomoon';
  src:url('/assets/icomoon.eot');
  src:url('/assets/icomoon.eot?#iefix') format('embedded-opentype'),
    url('/assets/icomoon.svg#icomoon') format('svg'),
    url('/assets/icomoon.woff') format('woff'),
    url('/assets/icomoon.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
}

Seems to work in development. But in HEROKU is does not seem to work. It cannot find /assets/icomoon.eot .

The solution in this link does not seem to work

Using fonts with Rails asset pipeline

解决方案

Assets like fonts will work on development but not production if you are using regular old css to locate your assets rather than the asset pipeline helpers. Rails 4 added breaking changes to the asset pipeline to encourage people to use it properly, and not use the old css method of referencing assets.

To resolve this, you need to use the new asset pipeline helpers to point to the fingerprinted, cached versions of your fonts. Rather than url (which does not use the asset pipeline), you need to use font-url (which does use it). To do this, you may have to use Sass or embed ERB in your stylesheet.

Example (using SCSS):

@font-face {
  font-family: 'Icomoon';
  src: font-url("/assets/icomoon.eot");
  src: font-url("/assets/icomoon.eot?#iefix") format("embedded-opentype"), font-url("/assets/icomoon.svg#icomoon") format("svg"), font-url("/assets/icomoon.woff") format("woff"), font-url("/assets/icomoon.ttf") format("truetype");
  font-weight: normal;
  font-style: normal;
}

See here: http://guides.rubyonrails.org/asset_pipeline.html#coding-links-to-assets

这篇关于Heroku字体资产不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆