Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moving files from node_modules to wwwroot with gulp in VS2015 asp.net core 1.0 project

When I create a new ASP.NET Core 1.0 application I want to use npm instead of bower. So I delete bower.json and additionally delete everything pre-installed in the wwwroot/lib folder.

I add a package.json file to my solution with the following dev dependencies:

"devDependencies": {
    "bootstrap": "3.3.7",
    "jquery": "3.1.0",
    "jquery-validation": "1.15.1",
    "jquery-validation-unobtrusive": "3.2.6"
}

However, NPM downloads all of the libraries to a node_modules folder in the root of my project.

I believe this is what Gulp is for. Can someone please tell me how I can use gulp to send the distribution files from node_modules to my wwwroot directory. If there are any tutorials out there that I was unable to find, please link.

like image 678
Blake Rivell Avatar asked Aug 07 '16 15:08

Blake Rivell


1 Answers

Read this article https://wildermuth.com/2017/11/19/ASP-NET-Core-2-0-and-the-End-of-Bower I used this when I saw that there is bad support of bower in netcore 2.0

Do npm install xyz or yarn install xyz for each package in bower.json. Update gulp to copy stuff from node_modules to lib. Replace bower install with npm install or yarn install in *.csproj file.

Summary gulpfile:

var merge = require('merge-stream');

// Old bower behavior would be "*" in before and "" in after but you don't want that much.
var webpackages = {
    "requirejs": {"bin/*": "bin/" }
    // ...
}

gulp.task("dist_lib", function() {
    var streams=[];
    for (var package in webpackages)
       for (var item in webpackages[package])
           streams.push(gulp.src("node_modules/" + package + "/" + item)
               .pipe(gulp.dest("lib/" + package + "/" + webpackage[package][item])));
}
like image 184
Sergey Ostanevich Avatar answered Oct 13 '22 04:10

Sergey Ostanevich