Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install font awesome 5 with npm for scss usage

like title says, I can not install font awesome 5 with npm for scss purposes.

Trying to install version 5

Accoring to https://fontawesome.com/how-to-use/use-with-node-js

npm i --save @fortawesome/fontawesome

Looking through the installation in node_modules I see no scss file to hook up to. I tried including the styles.css file in my app.scss file but that did not work.

My setup for version 4:

package.json "font-awesome": "^4.7.0",

app.scss @import "node_modules/font-awesome/scss/font-awesome.scss";

Usage <i className="fa fa-save icon controlItem"></i>

Easy as pie. How can I achieve this with version 5?? Am I using the wrong package?


UPDATE

Apparently, just using @fortawesome/fontawesome is not eanough. The packages have been split up so you also have to select npm install --save @fortawesome/fontawesome-free-regular Still I have no success importing it

like image 258
ajthinking Avatar asked Mar 15 '18 15:03

ajthinking


People also ask

How do I add Font Awesome to SCSS?

Adding Font Awesome to Your CompileOpen your project's scss/variables. scss and edit the $fa-font-path variable to point to where you placed the webfonts folder. $fa-font-path: "../webfonts"; In your main SCSS compile file, import Font Awesome by adding the core styles file, @import "scss/fontawesome.

How do I import Fortawesome Font Awesome for free?

OR you can import the module in your js code. import '@fortawesome/fontawesome-free/js/all. js'; OR if you are using Sass, you can import the module in app.

How to install Font-Awesome with npm?

Install font-awesome using npm. This is the most maintainable way as npm update will refresh the dependencies for you. Adjust your paths to account for where scss file is located in your project: You can also use a shorter syntax using tilda (~) prefix:

How to load Font-Awesome using SCSS?

- GeeksforGeeks How to load font-awesome using SCSS ? In order to load font-awesome icons in SCSS you need to follow these steps: Install Font-Awesome starter kit: Go to the font-awesome website and download the free starter-kit for web. The public folder will contain your html and css files whereas the resources folder contains your scss files.

How to install Font-Awesome starter kit?

Install Font-Awesome starter kit: Go to the font-awesome website and download the free starter-kit for web. The public folder will contain your html and css files whereas the resources folder contains your scss files.

How do I install Font Awesome in angular?

Font Awesome has an official Angular component. npm install --save @fortawesome/fontawesome-svg-core npm install --save @fortawesome/free-<type>-svg-icons npm install --save @fortawesome/angular-fontawesome Note: Replace <type> with solid, brands or regular whatever type of icons you need. You can also install Vue and React components.


1 Answers

npm install --save-dev @fortawesome/fontawesome
npm install --save-dev @fortawesome/free-regular-svg-icons
npm install --save-dev @fortawesome/free-solid-svg-icons
npm install --save-dev @fortawesome/free-brands-svg-icons

In your app.js or equivalent Javascript file,

import fontawesome from '@fortawesome/fontawesome'
import regular from '@fortawesome/free-regular-svg-icons'
import solid from '@fortawesome/free-solid-svg-icons'
import brands from '@fortawesome/free-brands-svg-icons'

fontawesome.library.add(regular)
fontawesome.library.add(solid)
fontawesome.library.add(brands)

For usage, there are slight changes to the way the class names are being used. Please refer to the icons on Fontawesome site for the "full" class names.

Example

<i class="fas fa-chevron-left"></i>

Although the idea of adding all the 3 variants of fonts into the project seems to be a convenient thing, do beware that this will slow performance when building/compiling your project. Thus, it is highly recommended that you add the fonts you need instead of everything.

like image 95
Ru Chern Chong Avatar answered Sep 19 '22 09:09

Ru Chern Chong