问题
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
?
回答1:
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.
回答2:
There should be a package.json
file in the same directory with that node_modules
, you only need to copy it to the new location then run npm install
from the command-line to install the packages. Then the new modules will soon be available at the new location.
来源:https://stackoverflow.com/questions/40853725/tired-of-copying-node-modules-to-wwwroot-folder