Gulp

From Code Self Study Wiki
Jump to: navigation, search
$ npm install --save-dev gulp gulp-util gulp-browserify gulp-rename gulp-uglify

In the gulpfile.js:

var gulp = require("gulp");
var browserify = require("gulp-browserify");
var rename = require("gulp-rename");
var uglify = require("gulp-uglify");
 
gulp.task("js", function() {
    gulp.src("public/js/main.js")
        .pipe(browserify({ debug: true })) // only for dev
        .pipe(rename("public/js/bundle.js"))
        .pipe(gulp.dest("./"));
});
 
gulp.task("compress", function() {
    gulp.src("public/js/bundle.js")
        .pipe(uglify())
        .pipe(rename("public/js/min.js"))
        .pipe(gulp.dest("./"));
});
 
gulp.task("watch", function() {
    gulp.watch("public/js/**/*.js");
});

Then run gulp watch.