我无法让font-awesome
图标出现在Angular 6 SPA中。
我的SPA基于此处的git模板;
我已将包裹添加到我的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>
该图标未出现。谁能告诉我我在这里做错了吗?
答案 0 :(得分:1)
在角度/ cli故事中,如何添加超棒的字体:
在_variables.scss
中创建一个空文件src/.
,并将以下内容添加到_variables.scss:
$fa-font-path : '../node_modules/font-awesome/fonts';
在styles.scss中添加以下内容:
@import 'variables';
@import '../node_modules/font-awesome/scss/font-awesome';
答案 1 :(得分:0)
最好的方法是在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*/
}