Matthew Flynn
Matthew Flynn

Reputation: 3931

Integrating Font-Awesome with Webpack 4 and Angular 6

I am having trouble getting the font-awesome icons to appear in my Angular 6 SPA.

My SPA is based on the git template here;

Angular Webpack App

I have added the package to my package.json;

"dependencies": {
"@angular/animations": "^6.0.7",
"@angular/common": "^6.0.7",
"@angular/compiler": "^6.0.7",
"@angular/compiler-cli": "^6.0.7",
"@angular/core": "^6.0.7",
"@angular/forms": "^6.0.7",
"@angular/http": "^6.0.7",
"@angular/platform-browser": "^6.0.7",
"@angular/platform-browser-dynamic": "^6.0.7",
"@angular/platform-server": "^6.0.7",
"@angular/router": "^6.0.7",
"@angular/upgrade": "^6.0.7",
"@angular-devkit/core": "^0.6.8",
"@agm/core": "^1.0.0-beta.3",
"@ks89/angular-modal-gallery": "^6.2.0",
"angular2-useful-swiper": "5.0.1",
"bootstrap": "3.3.7",
"core-js": "2.5.7",
"ie-shim": "0.1.0",
"font-awesome": "^4.7.0",
"hammerjs": "2.0.8",
"mousetrap": "1.6.2",
"ngx-bootstrap": "^2.0.5",
"rxjs": "6.2.1",
"rxjs-compat": "6.2.1",
"zone.js": "^0.8.26"
},

I have then have the following in my vendor.js;

import "font-awesome/scss/font-awesome.scss";

The vendor.js is then includes an entry point in the webpack.dev.js;

However, when I run the command npm run-script build-dev (which completes with no errors) the site runs with no errors but when I use (for example)

 <i class="fa fa-4x fa-phone-square"></i>

the icon isn't appearing. Can anyone tell me what I doing wrong here?

Upvotes: 1

Views: 690

Answers (2)

Anoop Surendran
Anoop Surendran

Reputation: 302

The best way is add styles on the angular.json file.

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "restuarant-app": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "prefix": "app",
      "schematics": {},
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/restuarant-app",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.app.json",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [] /* add the path to font-awesome Here*/
    }

Upvotes: 0

Muhammed Albarmavi
Muhammed Albarmavi

Reputation: 24404

From angular/cli stories how to include font awesome :

Create an empty file _variables.scss in src/. and add the following to _variables.scss:

$fa-font-path : '../node_modules/font-awesome/fonts';

In styles.scss add the following:

@import 'variables';
@import '../node_modules/font-awesome/scss/font-awesome';

angular/cli include font awesome

Upvotes: 1

Related Questions