Using fonts with Rails asset pipeline

前端 未结 12 1812
慢半拍i
慢半拍i 2020-11-22 14:52

I have some fonts being configured in my Scss file like so:

@font-face {
  font-family: \'Icomoon\';
  src: asset-url(\'icoMoon.eot?#iefix\', font) format(\'         


        
12条回答
  •  一个人的身影
    2020-11-22 15:25

    Now here's a twist:

    You should place all fonts in app/assets/fonts/ as they WILL get precompiled in staging and production by default—they will get precompiled when pushed to heroku.

    Font files placed in vendor/assets will NOT be precompiled on staging or production by default — they will fail on heroku. Source!

    — @plapier, thoughtbot/bourbon

    I strongly believe that putting vendor fonts into vendor/assets/fonts makes a lot more sense than putting them into app/assets/fonts. With these 2 lines of extra configuration this has worked well for me (on Rails 4):

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

    — @jhilden, thoughtbot/bourbon

    I've also tested it on rails 4.0.0. Actually the last one line is enough to safely precompile fonts from vendor folder. Took a couple of hours to figure it out. Hope it helped someone.

提交回复
热议问题