5

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?

Nhan
  • 3,595
  • 6
  • 30
  • 38
wonderful world
  • 10,969
  • 20
  • 97
  • 194

2 Answers2

5

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.

Ivan Sivak
  • 7,178
  • 3
  • 36
  • 42
3

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.

Nhan
  • 3,595
  • 6
  • 30
  • 38