Tired of copying node_modules to wwwroot folder
Asked Answered
A

2

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?

Aerodonetics answered 28/11, 2016 at 21:20 Comment(0)
M
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.

Merle answered 29/11, 2016 at 15:59 Comment(0)
K
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.

Kyanize answered 29/11, 2016 at 8:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.