如何使用 SpaTemplates 在 Visual Studio 2017 中向 ASP.NET Core Angular 2 应用程序添加字体真棒 [英] How to add font awesome to ASP.NET Core Angular 2 application in Visual Studio 2017 with SpaTemplates

查看:20
本文介绍了如何使用 SpaTemplates 在 Visual Studio 2017 中向 ASP.NET Core Angular 2 应用程序添加字体真棒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Visual Studio 2017 中的单页应用程序模板来创建 Angular 2 应用程序.

I am using the Single Page Application Template in Visual Studio 2017 in order to create an Angular 2 application.

dotnet new --install Microsoft.AspNetCore.SpaTemplates::*

然后像这样创建应用程序:

And then created the application like this:

dotnet new angular

将第三方库(如 font awesome)导入 Angular 2 应用程序的推荐方式是什么?

What is the reccommended way of importing third Party libraries like font awesome into the Angular 2 application?

推荐答案

信用 原帖

这适用于 .NET Core 2,在您使用 dotnet new angular 创建 SPA 项目后:

This is for .NET Core 2, after you create a SPA Project using dotnet new angular:

  1. 进入项目根目录并安装包:npm install font-awesome --save.您现在应该在 package.json 依赖项中看到它.

  1. Go to the root of the project and install the package: npm install font-awesome --save. You should now see it in package.json dependencies.

然后转到 webpack.config.vendor.js 并将 font awesome 添加到不可摇树模块下的数组中:

After that go to webpack.config.vendor.js and add font awesome to the array under non tree shakable modules:

const nonTreeShakableModules = ['引导','bootstrap/dist/css/bootstrap.css','es6-promise','es6-垫片','事件源-polyfill','font-awesome/css/font-awesome.css','jquery',];

const nonTreeShakableModules = [ 'bootstrap', 'bootstrap/dist/css/bootstrap.css', 'es6-promise', 'es6-shim', 'event-source-polyfill', 'font-awesome/css/font-awesome.css', 'jquery', ];

现在我们需要告诉 webpack 我们添加了这个新包.因此,如果您在使用 npm install --save-dev npm-install-webpack-plugin 将其安装到项目的根目录之前还没有这样做.

Now we need to tell the webpack that we added this new package. So if you haven't done so before install this in the root of project with npm install --save-dev npm-install-webpack-plugin.

最后,在项目根目录下运行这个命令:webpack --config webpack.config.vendor.js

Finally, run this command in the root of project: webpack --config webpack.config.vendor.js

这篇关于如何使用 SpaTemplates 在 Visual Studio 2017 中向 ASP.NET Core Angular 2 应用程序添加字体真棒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆