如何从 asp.net vnext 项目中的 wwwroot 访问 node_modules 文件夹 [英] How to access node_modules folder from wwwroot in asp.net vnext project

查看:21
本文介绍了如何从 asp.net vnext 项目中的 wwwroot 访问 node_modules 文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从我的 index.html 所在的 wwwroot 访问未包含在 Visual Studio 解决方案文件中的 node_modules 文件夹.该 index.html 文件需要引用 npm 安装的包,如 angular.js.

How can I access the node_modules folder which is not included in the visual studio solution file from the wwwroot where my index.html is put. That index.html file need to reference the npm installed packages like angular.js.

但是怎么做呢?

我不想将整个 node_modules 文件夹复制到 wwwroot 中.那些不是存放在那里的文件......

I do not want to copy the whole node_modules folder into wwwroot. Those are not the files to live there...

我不想在解决方案中包含 node_modules 文件夹,因为这会减慢一切并挂断...

I do not want to include the node_modules folder to the solution because that will slow down everything and hang up...

似乎前端开发不属于VS...

It seems Frontend development belongs not in VS...

推荐答案

您不应该从 wwwroot 外部访问文件.wwwroot 文件夹是公用文件夹,当您托管它时,可从外部访问.

You are not supposed to access files from outside of wwwroot. The wwwroot folder is the public folder that's accessible from outside, when you host it.

上面的一切都是禁区.

典型的发布过程是,当你的 ASP.NET web 项目被编译或发布时,你有一个 gulp 或 grunt 任务运行,它会在那里运行任务并复制 wwwroot 文件夹,即 wwwroot/libswwwdata/js.

The typical publishing process is, that you have a gulp or grunt task that runs when your ASP.NET webproject is compiled or published, it would run the tasks there and copy over the necessary files inside wwwroot folder, i.e. wwwroot/libs or wwwdata/js.

当然,您也可以手动复制文件,但这很糟糕,尤其是当您更新许多依赖项时,很难手动跟踪.

Of course you can also manually copy the files over, but that's rather bad especially when you update many dependencies it's hard to keep track manually.

虽然它没有显示在解决方案中(只是间接地,在 Dependencies/npm 部分中),您仍然可以通过点击解决方案资源管理器顶部的显示所有文件"按钮使其可见并复制您需要的文件.

While it's not displayed in the solution (just indirectly, in the Dependencies/npm section), you can still make it visible by hitting the "Show all files" button on top of the Solution Explorer and copy over the files you need.

不过最好给它设置一个gulp任务,不过这不在本题的范围内.

But it's best to set up a gulp task for it, but that's out of the scope of this question.

这篇关于如何从 asp.net vnext 项目中的 wwwroot 访问 node_modules 文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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