Rails 5 - 生产环境下无法加载供应商资产 (仅限字体)

3

在开发环境中完美运行,但在生产环境中无法正常工作。它找不到以下文件:

/assets/fontello.woff
/assets/fontello.ttf

设置如下:

  1. 字体文件:

enter image description here

  1. assets.rb

    Rails.application.config.assets.paths << Rails.root.join('app', 'vendor', 'assets', 'fonts')
    Rails.application.config.assets.precompile << /\.(?:svg|eot|woff|ttf)\z/
    
  2. fontello.css

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

就像我之前说的,开发环境下一切都工作得很好。我尝试了很多事情,例如:

  1. moving the fonts in the public folder (as my images there are loaded)
  2. add the following line in the assets.rb:

    Rails.application.config.assets.precompile += [/^[-_a-zA-Z0-9]*\..*/]
    

但是什么都没用。

你能建议其他尝试的方法吗?

1个回答

6
在生产环境中,ls public/assets 会输出什么?
很可能你的文件已经有了摘要(例如 fontello-XXXX.ttf)。在这种情况下,您需要在您的sass(而不是css)中使用字体帮助程序 - 例如,在您的font-family块中:src:font-url('fontello.ttf')

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接