如何使用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
问题描述
我在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
将诸如真棒字体之类的第三方库导入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:
-
转到项目的根目录并安装软件包:npm install font-awesome --save.您现在应该在package.json依赖项中看到它.
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并将非凡的字体添加到非树可晃动模块下的数组中:
After that go to webpack.config.vendor.js and add font awesome to the array under non tree shakable modules:
const nonTreeShakableModules = [ 'bootstrap', 'bootstrap/dist/css/bootstrap.css', 'es6-promise', 'es6-shim', 事件源-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屋!