Skip to content

Instantly share code, notes, and snippets.

@spboyer
Created March 6, 2015 18:45
Show Gist options
  • Save spboyer/5180a9eca4ed1b496c1b to your computer and use it in GitHub Desktop.
Save spboyer/5180a9eca4ed1b496c1b to your computer and use it in GitHub Desktop.
Gulp equivalent of grunt for VS2015 web template
var gulp = require('gulp');
var mainBowerFiles = require('main-bower-files');
var $ = require('gulp-load-plugins')({
lazy: true
});
gulp.task('bower', function () {
return $.bower()
});
gulp.task('default', ['bower'], function () {
return gulp.src(mainBowerFiles())
.pipe(gulp.dest("wwwroot/lib"));
});
{
"version": "0.0.0",
"name": "TestWebApp",
"devDependencies": {
"del": "^1.1.1",
"gulp": "^3.8.10",
"gulp-bower": "0.0.10",
"gulp-load-plugins": "^0.8.1",
"main-bower-files": "^2.5.0"
}
}
@madskristensen
Copy link

Here's what we are looking at to replace the gulpfile.js in the VS tools:

var gulp = require("gulp"),
    rimraf = require("rimraf"),
    fs = require("fs");

eval("var project = " + fs.readFileSync("./project.json"));

var paths = {
    bower: "./bower_components/",
    lib: "./" + project.webroot + "/lib/"
};

gulp.task("clean", function (cb) {
    rimraf(paths.lib, cb);
});

gulp.task("copy", ["clean"], function () {
    var bower = {
        "boostrap": "bootstrap/dist/**/*.{js,map,css,ttf,svg,woff,eot}",
        "boostrap-touch-carousel": "bootstrap-touch-carousel/dist/**/*.{js,css}",
        "hammer.js": "hammer.js/hammer*.{js,map}",
        "jquery": "jquery/jquery*.{js,map}",
        "jquery-validation": "jquery-validation/jquery.validate.js",
        "jquery-validation-unobtrusive": "jquery-validation-unobtrusive/jquery.validate.unobtrusive.js"
    };

    for (var destinationDir in bower) {
        gulp.src(paths.bower + bower[destinationDir])
            .pipe(gulp.dest(paths.lib + destinationDir));
    }
});

The benefit here is that only gulp and rimraf node modules are required

@spboyer
Copy link
Author

spboyer commented Mar 6, 2015

@madskristensen for the initial template that works, however by comparison to the grunt version it does not inherently include additional packages if the user adds them to the package.json. They would also have to add them to the copy task here.

@johnpapa
Copy link

You should chuck rimraf. It's an external package that effectively does what node does out of the box with del. Use require('del') instead.

The bower wire-up is messy and error prone (magic strings). I recommend using wiredep here as it "just works" and works even when you add more bower files. Happy to help contribute if you want.

@johnpapa
Copy link

as a side note, if you want a default gulpfile, happy to help there too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment