You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在React.js中通过npm安装FontAwesome最新版(5.0.10)

How to Install Font Awesome 5.0.10 via npm Correctly

Hey there! The issue with your initial command is that Font Awesome 5 splits its functionality into separate packages—you need both the core framework and the icon packs to get everything working properly. Let's fix this step by step:

1. Install the Core Framework

First, install the core Font Awesome package pinned to version 5.0.10:

npm install @fortawesome/fontawesome@5.0.10 --save

2. Install Icon Packs (Free Versions)

Next, add the icon styles you need. Pick one or more of these commands depending on which icons you want to use:

  • For solid-style icons:
    npm install @fortawesome/free-solid-svg-icons@5.0.10 --save
    
  • For regular-style icons:
    npm install @fortawesome/free-regular-svg-icons@5.0.10 --save
    
  • For brand icons (like Twitter, GitHub):
    npm install @fortawesome/free-brands-svg-icons@5.0.10 --save
    

Alternative: Install the Full Free CSS Package

If you prefer using the CSS version of Font Awesome (instead of the SVG/JS approach), you can install a single package that includes the core CSS and all free icons in one go:

npm install @fortawesome/fontawesome-free@5.0.10 --save

Quick Usage Examples

For SVG/JS Approach

In your JavaScript file, import and register the icons you need:

import fontawesome from '@fortawesome/fontawesome'
import { faCoffee, faUser } from '@fortawesome/free-solid-svg-icons'

// Add individual icons to the library for global use
fontawesome.library.add(faCoffee, faUser)

For CSS Approach

Import the CSS file in your main stylesheet or entry JavaScript file:

import '@fortawesome/fontawesome-free/css/all.css'

That should get Font Awesome 5.0.10 up and running smoothly in your project!

内容的提问来源于stack exchange,提问作者Developer Strange

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 08:06:08