Among other things, fontawesome now comes only in one package @fortawesome/fontawesome-free which includes all the icons.
But basically solidIcons or faUser or whatever is not defined. Any idea how to do?
import { Controller } from “@hotwired/stimulus”
import fontawesome from ‘@fortawesome/fontawesome-free’
import solidIcons from ‘@fortawesome/fontawesome-free’
// Connects to data-controller=“fontawesome”
export default class extends Controller {
// register icons we want to use in our app
initialize() {
// we can add all icons at once
//fontawesome.library.add(regularIcons)
fontawesome.library.add(solidIcons)
//fontawesome.library.add(solidSvgIcons)
// or we can add icons individually
//fontawesome.library.add([
// faUser
//])
}
// tell Font Awesome to convert icons every time the controller connects
The reason is that adding FontAwesome to your bundle will just make it much bigger for no practical reason. You are not going to interact with it in your JavaScript anyway, so it seems a good idea to load it independently of the rest of your JS.
If for any reason, you prefer not to use a public CDN, you can serve it directly from your vendor directory.
application.js gets the fontawesome js and the css_loader compiles the fontawesome css into applicaition.css which I include with the respective rails helpers.