【问题标题】:Integrating Font-Awesome with Webpack 4 and Angular 6将 Font-Awesome 与 Webpack 4 和 Angular 6 集成
【发布时间】:2019-01-14 10:01:12
【问题描述】:

我无法让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 webpack webpack-4


    【解决方案1】:

    从 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

    【讨论】:

      【解决方案2】:

      最好的方法是在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*/
          }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-08-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-07-23
        • 1970-01-01
        相关资源
        最近更新 更多