2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Rails7構築 -その3- importmapでfontawesomeを導入

Last updated at Posted at 2023-01-09

↓その2の続き

bootstrap5の後にFontAwesomeを導入します。

参考

ほぼここのまんまです。

yarnでfortawesomeをインストール

$ yarn add @fortawesome/fontawesome-free

インストールしたfontawesomeをimportmapにpinします。

$ ./bin/importmap pin @fortawesome/fontawesome-free

config/importmap.rbを変更

fontawesome.js→all.jsに変更

importmap.rb
# pin "@fortawesome/fontawesome-free", to: "https://ga.jspm.io/npm:@fortawesome/fontawesome-free@6.2.1/js/fontawesome.js
pin "@fortawesome/fontawesome-free", to: "https://ga.jspm.io/npm:@fortawesome/fontawesome-free@6.2.1/js/all.js

app/javascript/application.jsにfontawesomeをimport

app/javascript/application.js
//= require jquery3
//= require popper
//= require bootstrap-sprockets
import "@hotwired/turbo-rails"
import "controllers"
import "@fortawesome/fontawesome-free"

確認

fontawesomeのアイコンを追加

index.erb
<h1>
<i class="fas fa-space-shuttle"></i>
<i class="fas fa-snowman"></i>
<i class="fas fa-kiwi-bird"></i>
</h1>

表示されました
fontawesome.png

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?