\n\n```\n\n## スタイルを読みこんでおく\n\nリロード時などに Font Awesome のアイコンの表示が崩れないように事前に Style を読みこんでおくために、`gatsby-broeser.js` に以下を追記。\n\n```js\n// CSS style for Font Awesome\nimport \"@fortawesome/fontawesome-svg-core/styles.css\"\n```\n\n無事にアイコンが表示できたはず 🎉\n\n## 2025年追記: 現在のアイコン実装\n\n2025年にGatsbyからAstroに移行した際、アイコン実装も見直しました。\n\nhttps://nawo.to/2025/06/17/migrate-to-astro-by-ai/\n\n### 現在の実装\n\n**Font Awesome → Simple Icons + カスタムSVG**\n\n- **Simple Icons**: 主要ブランド(X, GitHub, Instagram等)\n- **カスタムSVG**: マイナーなブランド(Suzuri, SpeakerDeck等)\n- **Font Awesome**: 使用していない\n\nhttps://simpleicons.org/\n\n### 変更理由\n\n1. **バンドルサイズ削減**: Font Awesomeは重い\n2. **パフォーマンス向上**: SVGは軽量\n3. **依存関係簡素化**: 必要なアイコンのみ実装\n\n### 現在の実装例\n\n```typescript\n// src/data/icons.ts\nimport { siX } from 'simple-icons';\n\nexport const iconData = {\n // Simple Icons使用\n x: {\n viewBox: '0 0 24 24',\n path: siX.path\n },\n // カスタムSVG\n suzuri: {\n viewBox: '0 0 640 512',\n path: 'M211.8 0c7.8 0 14.3 5.7 16.7 13.2...'\n }\n}\n```\n\n### 使用例\n\n```astro\n\n\n\n```\n\nより効率的で軽量な実装になりました!","filePath":"src/content/logs/2022/2022-05-11-install-font-awesome.md","digest":"ad3edf323d98682a","rendered":{"html":"
自分の SNS アカウントへのリンクは、アイコンのみで良さそうなので Font Awesome を導入した。\n(個人的にはタイポグラフィなサイトが好みなので、文字多めな傾向はある。)
\n必要な Package をインストール
\nこのサイトは、Gatsby で作っているので、React で利用するのとほぼ一緒な感じで設定した。
\n$ npm i --save @fortawesome/fontawesome-svg-core\n$ npm i --save @fortawesome/react-fontawesome
\n次に必要な icon の方もインストール。\nTwitter のアイコンなどを含んでいる ‘brands’ と Feed アイコンをいったアイコンも使いたいので ‘solid’ の方をインストール。
\n$ npm i --save @fortawesome/free-solid-svg-icons\n$ npm i --save @fortawesome/free-brands-svg-icons
\n実際に使ってみる
\n使いたい箇所のコンポーネントをゴニョゴニョ修正。\nFont Awesome で使いたいアイコンを探して、表記を camel case に読みかえて import する。
\nimport { FontAwesomeIcon } from \"@fortawesome/react-fontawesome\"\nimport { faSquareRss } from \"@fortawesome/free-solid-svg-icons\"\nimport {\n faTwitter,\n faGithub,\n faSpeakerDeck,\n faInstagram,\n} from \"@fortawesome/free-brands-svg-icons\"
\nあとは使いたい箇所で、以下のようにアイコンを呼びだせば表示された。
\n<a href=\"https://twitter.com/nawoto\">\n <FontAwesomeIcon icon={faTwitter} />\n</a>
\nスタイルを読みこんでおく
\nリロード時などに Font Awesome のアイコンの表示が崩れないように事前に Style を読みこんでおくために、gatsby-broeser.js
に以下を追記。
\n// CSS style for Font Awesome\nimport \"@fortawesome/fontawesome-svg-core/styles.css\"
\n無事にアイコンが表示できたはず 🎉
\n2025年追記: 現在のアイコン実装
\n2025年にGatsbyからAstroに移行した際、アイコン実装も見直しました。
\n\n現在の実装
\nFont Awesome → Simple Icons + カスタムSVG
\n\n- Simple Icons: 主要ブランド(X, GitHub, Instagram等)
\n- カスタムSVG: マイナーなブランド(Suzuri, SpeakerDeck等)
\n- Font Awesome: 使用していない
\n
\n\n変更理由
\n\n- バンドルサイズ削減: Font Awesomeは重い
\n- パフォーマンス向上: SVGは軽量
\n- 依存関係簡素化: 必要なアイコンのみ実装
\n
\n現在の実装例
\n// src/data/icons.ts\nimport { siX } from 'simple-icons';\n\nexport const iconData = {\n // Simple Icons使用\n x: {\n viewBox: '0 0 24 24',\n path: siX.path\n },\n // カスタムSVG\n suzuri: {\n viewBox: '0 0 640 512',\n path: 'M211.8 0c7.8 0 14.3 5.7 16.7 13.2...'\n }\n}
\n使用例
\n<!-- src/components/Icon.astro -->\n<Icon name=\"x\" class=\"w-6 h-6\" />\n<Icon name=\"suzuri\" class=\"w-6 h-6\" />
\nより効率的で軽量な実装になりました!
","metadata":{"headings":[{"depth":2,"slug":"必要な-package-をインストール","text":"必要な Package をインストール"},{"depth":2,"slug":"実際に使ってみる","text":"実際に使ってみる"},{"depth":2,"slug":"スタイルを読みこんでおく","text":"スタイルを読みこんでおく"},{"depth":2,"slug":"2025年追記-現在のアイコン実装","text":"2025年追記: 現在のアイコン実装"},{"depth":3,"slug":"現在の実装","text":"現在の実装"},{"depth":3,"slug":"変更理由","text":"変更理由"},{"depth":3,"slug":"現在の実装例","text":"現在の実装例"},{"depth":3,"slug":"使用例","text":"使用例"}],"localImagePaths":[],"remoteImagePaths":[],"frontmatter":{"title":"Font Awesome を使おう","pubDate":"2022-05-11T00:00:00.000Z","description":""},"imagePaths":[]}},"collection":"logs","slug":"2022/2022-05-11-install-font-awesome","url":"https://nawo.to/2022/05/11/install-font-awesome","headline":"Font Awesome を使おう","description":"自分の SNS アカウントへのリンクは、アイコンのみで良さそうなので Font Awesome を導入した。 (個人的にはタイポグラフィなサイトが好みなので、文字多めな傾向はある。) 必要な Package をインストール このサイトは、Gatsby で作っているので、React で利用するのとほぼ一緒な感じで設定した...","image":"https://nawo.to/logs/2022/2022-05-11-install-font-awesome/og.png","author":{"@type":"Person","name":"NISHIMURA Naoto","url":"https://nawo.to"},"publisher":{"@type":"Organization","name":"#nawoto","logo":{"@type":"ImageObject","url":"https://nawo.to/images/site-icon.png"}},"datePublished":"2022-05-11T00:00:00.000Z","dateModified":"2022-05-11T00:00:00.000Z","mainEntityOfPage":{"@type":"WebPage","@id":"https://nawo.to/2022/05/11/install-font-awesome"}}
Font Awesome を使おう
自分の SNS アカウントへのリンクは、アイコンのみで良さそうなので Font Awesome を導入した。
(個人的にはタイポグラフィなサイトが好みなので、文字多めな傾向はある。)
必要な Package をインストール
このサイトは、Gatsby で作っているので、React で利用するのとほぼ一緒な感じで設定した。
$ npm i --save @fortawesome/fontawesome-svg-core
$ npm i --save @fortawesome/react-fontawesome
次に必要な icon の方もインストール。
Twitter のアイコンなどを含んでいる ‘brands’ と Feed アイコンをいったアイコンも使いたいので ‘solid’ の方をインストール。
$ npm i --save @fortawesome/free-solid-svg-icons
$ npm i --save @fortawesome/free-brands-svg-icons
実際に使ってみる
使いたい箇所のコンポーネントをゴニョゴニョ修正。
Font Awesome で使いたいアイコンを探して、表記を camel case に読みかえて import する。
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
import { faSquareRss } from "@fortawesome/free-solid-svg-icons"
import {
faTwitter,
faGithub,
faSpeakerDeck,
faInstagram,
} from "@fortawesome/free-brands-svg-icons"
あとは使いたい箇所で、以下のようにアイコンを呼びだせば表示された。
<a href="https://twitter.com/nawoto">
<FontAwesomeIcon icon={faTwitter} />
</a>
スタイルを読みこんでおく
リロード時などに Font Awesome のアイコンの表示が崩れないように事前に Style を読みこんでおくために、gatsby-broeser.js
に以下を追記。
// CSS style for Font Awesome
import "@fortawesome/fontawesome-svg-core/styles.css"
無事にアイコンが表示できたはず 🎉
2025年追記: 現在のアイコン実装
2025年にGatsbyからAstroに移行した際、アイコン実装も見直しました。
現在の実装
Font Awesome → Simple Icons + カスタムSVG
- Simple Icons: 主要ブランド(X, GitHub, Instagram等)
- カスタムSVG: マイナーなブランド(Suzuri, SpeakerDeck等)
- Font Awesome: 使用していない
変更理由
- バンドルサイズ削減: Font Awesomeは重い
- パフォーマンス向上: SVGは軽量
- 依存関係簡素化: 必要なアイコンのみ実装
現在の実装例
// src/data/icons.ts
import { siX } from 'simple-icons';
export const iconData = {
// Simple Icons使用
x: {
viewBox: '0 0 24 24',
path: siX.path
},
// カスタムSVG
suzuri: {
viewBox: '0 0 640 512',
path: 'M211.8 0c7.8 0 14.3 5.7 16.7 13.2...'
}
}
使用例
<!-- src/components/Icon.astro -->
<Icon name="x" class="w-6 h-6" />
<Icon name="suzuri" class="w-6 h-6" />
より効率的で軽量な実装になりました!