在生产模式下无法通过资产管道加载网络字体
web fonts not loading through asset pipeline in production mode
我正在尝试将 myfonts.com 中的一些网络字体加载到我在 DigitalOcean 上的 rails 应用程序 运行 中。它似乎预编译工作得很好,它在 'development' 模式下在本地工作,但不会在 'production' 模式下加载文件。
这些问题的其他答案指向资产管道,但解决方案没有帮助。
我的文件夹结构如下所示:
app
|assets
||fonts
|||*various font files*
main.scss
@import url("//hello.myfonts.net/count/30b86b");
@font-face {
font-family: 'SofiaProExtraLight';
src: asset-url('30B86B_0_0.eot');
src: asset-url('30B86B_0_0.eot?#iefix') format('embedded-opentype'),asset-url('30B86B_0_0.woff2') format('woff2'),asset-url('30B86B_0_0.woff') format('woff'),asset-url('30B86B_0_0.ttf') format('truetype');
}
@font-face {
font-family: 'SofiaProSemiBold';
src: asset-url('30B86B_1_0.eot');
src: asset-url('30B86B_1_0.eot?#iefix') format('embedded-opentype'),asset-url('30B86B_1_0.woff2') format('woff2'),asset-url('30B86B_1_0.woff') format('woff'),asset-url('30B86B_1_0.ttf') format('truetype');
}
@font-face {
font-family: 'SofiaProRegular';
src: asset-url('30B86B_2_0.eot');
src: asset-url('30B86B_2_0.eot?#iefix') format('embedded-opentype'),asset-url('30B86B_2_0.woff2') format('woff2'),asset-url('30B86B_2_0.woff') format('woff'),asset-url('30B86B_2_0.ttf') format('truetype');
}
只需将此添加到您的 application.rb
:
module MyApp
class Application < Rails::Application
# ...
config.assets.paths += %w(fonts)
end
end
我正在尝试将 myfonts.com 中的一些网络字体加载到我在 DigitalOcean 上的 rails 应用程序 运行 中。它似乎预编译工作得很好,它在 'development' 模式下在本地工作,但不会在 'production' 模式下加载文件。
这些问题的其他答案指向资产管道,但解决方案没有帮助。
我的文件夹结构如下所示:
app
|assets
||fonts
|||*various font files*
main.scss
@import url("//hello.myfonts.net/count/30b86b");
@font-face {
font-family: 'SofiaProExtraLight';
src: asset-url('30B86B_0_0.eot');
src: asset-url('30B86B_0_0.eot?#iefix') format('embedded-opentype'),asset-url('30B86B_0_0.woff2') format('woff2'),asset-url('30B86B_0_0.woff') format('woff'),asset-url('30B86B_0_0.ttf') format('truetype');
}
@font-face {
font-family: 'SofiaProSemiBold';
src: asset-url('30B86B_1_0.eot');
src: asset-url('30B86B_1_0.eot?#iefix') format('embedded-opentype'),asset-url('30B86B_1_0.woff2') format('woff2'),asset-url('30B86B_1_0.woff') format('woff'),asset-url('30B86B_1_0.ttf') format('truetype');
}
@font-face {
font-family: 'SofiaProRegular';
src: asset-url('30B86B_2_0.eot');
src: asset-url('30B86B_2_0.eot?#iefix') format('embedded-opentype'),asset-url('30B86B_2_0.woff2') format('woff2'),asset-url('30B86B_2_0.woff') format('woff'),asset-url('30B86B_2_0.ttf') format('truetype');
}
只需将此添加到您的 application.rb
:
module MyApp
class Application < Rails::Application
# ...
config.assets.paths += %w(fonts)
end
end