Sample application to show how to integrate Font Awesome 5 SVG Framework with Ruby on Rails 5.
It will take advantage of the webpacker gem, with tree shaking support out of the box.
$ rails new fontawesome5demo --webpack
$ yarn add @fortawesome/fontawesome-svg-core@^1.2.13
$ yarn add @fortawesome/free-brands-svg-icons@^5.7.0
$ yarn add @fortawesome/free-regular-svg-icons@^5.7.0
$ yarn add @fortawesome/free-solid-svg-icons@^5.7.0
Let's say you need fas fa-star
, far fa-star
, and fab fa-font-awesome
.
Add this to your /app/javascript/packs/application.js
:
import { library, dom } from '@fortawesome/fontawesome-svg-core'
import {
faFontAwesome
} from '@fortawesome/free-brands-svg-icons'
import {
faStar as farFaStar
} from '@fortawesome/free-regular-svg-icons';
import {
faStar as fasFaStar
} from '@fortawesome/free-solid-svg-icons';
library.add(
faFontAwesome,
farFaStar,
fasFaStar
);
dom.watch()
Refer to https://fontawesome.com/how-to-use/use-with-node-js for the whole documentation
Font Awesome 5.7.0 supports Turbolinks out of the box. For older versions (< 5.7.0, >= 5.1.0), please replace:
dom.watch()
with
// Change `observeMutationsRoot` value to `document`
// to ensure compatibility with Turbolinks
dom.watch({ observeMutationsRoot: document })
The standard location is /app/views/layouts/application.html.erb
Add this into the head element:
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
Yes. Please refer to webpacker documentation
Yes. Please refer to webpacker documentation