Ruby on Rails + Yarn + Font Awesome in Production, final solution

One of the biggest advances in the Web Development Framework, Ruby On Rails, was the official inclusion of an asset manager, in this case, Yarn. Now it is possible to get rid of, in a more practical way, a multitude of GEMs that were there in our Gemfile just for that purpose.


However, some tools, such as the famous Font Awesome, which needs fonts are a complication when put into Production environment, after the assets-precompile and the digest are put in place. What happens, font-awesome does not work.

So let's solve this problem in a simple way:

Step 1: Normally add font-awesome with yarn

yarn add font-awesome

Step 2: Make sure path is declared in config/initializers/assets.rb

Look for something like this: Rails.application.config.assets.paths << Rails.root.join('node_modules'), this is added by default in Rails 5, but if you did it in a custom way, it could look like this: Rails.application.config.assets.paths << Rails.root.join('vendor/assets').

Step 3: Do not suck to simply import font-awesome into app/assets/stylesheets/application.scss like this: *= require font-awesome/scss/font-awesome. Create the following file, you can name it like this app/assets/stylesheets/font-awesome-overwrite.scss



Finally, import the in app/assets/stylesheets/application.scss this way:  *= require font-awesome-overwrite

Okay, now your project will work with the font-awesome in both Development and Production
Ruby on Rails + Yarn + Font Awesome in Production, final solution  Ruby on Rails + Yarn + Font Awesome in Production, final solution Reviewed by AJ Alves on quarta-feira, junho 27, 2018 Rating: 5

Nenhum comentário:

Tecnologia do Blogger.