厌倦了将node_modules复制到wwwroot文件夹 [英] Tired of copying node_modules to wwwroot folder
问题描述
我有一个带有大量Node.js模块的ASP.NET 5项目。它们安装在 node_modules
文件夹下。
在开发环境(environment = development)中,手动模块< wwwroot \lib
。当这变得乏味时,我写了一个Gulp任务来复制它们。现在有很多任务。
是否有任何ASP.NET项目设置,以便可以从 node_modules $ c $加载模块c>文件夹在根目录而不是从
wwwroot \ lib
?
编辑:为了开发目的,只需添加一个 UseStaticFiles
中间件。你的 Startup.cs
- > public void Configure()
method - >添加:
app.UseStaticFiles();
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(),@node_modules)),
RequestPath = new PathString(/ node_modules)
});
UseStaticFiles
被使用了两次。首先,从默认的 wwwroot
提供静态文件,第二次为 / node_modules
文件提供服务。如此处所述。
请在生产环境中小心。
I have an ASP.NET 5 project with a plenty of Node.js modules. They are installed under the node_modules
folder.
In the development environment (environment=development), I started copying all the modules to wwwroot\lib
manually. When that became tedious, I wrote a Gulp task to copy them. Now there are plenty of tasks.
Is there any ASP.NET project setting so the modules can be loaded from the node_modules
folder at the root rather than from the wwwroot\lib
?
Edit: For development purposes, just add one more UseStaticFiles
middleware. To your Startup.cs
-> public void Configure()
method -> Add this:
app.UseStaticFiles();
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), @"node_modules")),
RequestPath = new PathString("/node_modules")
});
UseStaticFiles
is used twice. First, to serve static files from a default wwwroot
and the second time to serve /node_modules
files. As described here.
Just be careful in production environment.
这篇关于厌倦了将node_modules复制到wwwroot文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!