Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tired of copying node_modules to wwwroot folder

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?

like image 697
wonderful world Avatar asked Nov 28 '16 21:11

wonderful world


2 Answers

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.

like image 143
Ivan Sivak Avatar answered Sep 30 '22 19:09

Ivan Sivak


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.

like image 44
Nhan Avatar answered Sep 30 '22 20:09

Nhan