如何在React.js中通过npm安装FontAwesome最新版(5.0.10)
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

