Heroku 字体资产不起作用 [英] Heroku font assets not working
问题描述
在app/assets/fonts
已添加
Add the fonts path
config.assets.paths << Rails.root.join('app', 'assets', 'fonts')
Precompile additional assets
config.assets.precompile += %w( .svg .eot .woff .ttf )
在 production.rb 和 development.rb 中
in production.rb and development.rb
在 css 中链接的字体,例如:
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;
}
似乎正在开发中.但在 HEROKU 中似乎不起作用.它找不到/assets/icomoon.eot .
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
推荐答案
如果您使用常规的旧 css 而不是资产管道助手来定位您的资产,则字体等资产将适用于开发,但不适用于生产.Rails 4 对资产管道进行了重大更改,以鼓励人们正确使用它,而不是使用旧的 css 方法来引用资产.
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.
要解决此问题,您需要使用新的资产管道助手来指向字体的指纹缓存版本.而不是 url
(它不使用资产管道),您需要使用 font-url
(它确实使用它).为此,您可能必须使用 Sass 或在样式表中嵌入 ERB.
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.
示例(使用 SCSS):
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;
}
参见此处:http://guides.rubyonrails.org/asset_pipeline.html#coding-links-to-assets
这篇关于Heroku 字体资产不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!