将 Font-Awesome 与 Webpack 4 和 Angular 6 集成

Integrating Font-Awesome with Webpack 4 and Angular 6

我无法让 font-awesome 图标出现在我的 Angular 6 SPA 中。

我的 SPA 基于此处的 git 模板;

Angular Webpack App

我已将包添加到我的 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"
},

然后我的 vendor.js;

中有以下内容
import "font-awesome/scss/font-awesome.scss";

vendor.js 然后在 webpack.dev.js 中包含一个入口点;

但是,当我 运行 命令 npm run-script build-dev(完成且没有错误)时,站点 运行 没有错误但是当我使用(例如)

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

图标没有出现。谁能告诉我我做错了什么?

来自 angular/cli 个故事如何包含很棒的字体 :

src/. 中创建一个空文件 _variables.scss 并将以下内容添加到 _variables.scss:

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

在styles.scss中添加以下内容:

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

angular/cli include font awesome

最好的方法是在 angular.json 文件中添加样式。

{
  "$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*/
    }