如何在Visual Studio 2017中将npm软件包与ASP.NET CORE 2一起使用?

编程入门 行业动态 更新时间:2024-10-23 17:34:02
本文介绍了如何在Visual Studio 2017中将npm软件包与ASP.NET CORE 2一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在Visual Studio 2017的ASP.NET Core 2项目中添加了一些npm程序包.现在,我想使用这些程序包中的css和js文件,但是VS看不到它们,因为node_modules文件夹位于wwwroot之外.此处的常见做法是如何使Visual Studio与node_modules一起使用?

I added some npm packages to my ASP.NET Core 2 project in Visual Studio 2017. Now I want to use css and js files from these packages, but VS doesn't see them because node_modules folder is outside wwwroot. What is the common practice here, how to make Visual Studio working with node_modules?

推荐答案

常见的做法是捆绑您的Web资产,并且仅将编译后的捆绑软件放入您的wwwroot文件夹中.

The common practice is to bundle your web assets, and put only the compiled bundle into your wwwroot folder.

自Visual Studio 2015以来,我们有来自NPM World的多个Taskrunner:

Since Visual Studio 2015 we have multiple Taskrunners from the NPM World:

  • Gulp
  • 矮人

与他们一起,您可以编写一个脚本,该脚本会自动捆绑您的Web资产.该脚本具有对NPM基础结构的完全访问权限.

With them you could write a script, which automatically bundles your web assets. This script has full access to the NPM infrastructure.

有一些工具可以使超级简单:

There are some tools out there which make this super easy:

  • gulp-uglify
  • gulp-cssmin

更多信息: docs.microsoft/zh-我们/aspnet/core/client-side/using-gulp

也就是说,它也是可能包括您的npm文件夹:

That said, it is also possible to include your npm folder:

public void Configure(IApplicationBuilder app) { app.UseStaticFiles(); // For the wwwroot folder app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider( Path.Combine(Directory.GetCurrentDirectory(), "node_modules")), RequestPath = "/node_modules" }); }

但这是错误的方法.

更多推荐

如何在Visual Studio 2017中将npm软件包与ASP.NET CORE 2一起使用?

本文发布于:2023-11-14 04:39:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1586242.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:软件包   中将   如何在   Studio   Visual

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!