Skip to content

Instantly share code, notes, and snippets.

@floatdrop
Forked from yocontra/watchem.js
Last active November 24, 2016 02:36
Show Gist options
  • Save floatdrop/8262616 to your computer and use it in GitHub Desktop.
Save floatdrop/8262616 to your computer and use it in GitHub Desktop.
var gulp = require('gulp');
var browserify = require('gulp-browserify');
var less = require('gulp-less');
var concat = require('gulp-concat');
var jshint = require('gulp-jshint');
var watch = require('gulp-watch');
var outDir = './temp';
var isWatch = false;
var sources = {
scripts: './app/scripts/**/*.js',
less: './app/styles/**/*.less',
copy: './app/images/*',
browserify: './app/scripts/main.js'
};
function watchOrNot(files) {
return isWatch ? gulp.src(files).pipe(watch()) : gulp.src(files);
}
gulp.task('watch', function () {
isWatching = true;
gulp.run('default');
});
gulp.task('default', function () {
gulp.run('copy', 'less', 'jshint', 'browserify');
});
gulp.task('copy', function () {
watchOrNot(sources.copy)
.pipe(gulp.dest(outDir + '/images'))
});
gulp.task('less', function () {
watchOrNot(sources.less)
.pipe(less({compress: false}))
.pipe(gulp.dest(outDir + '/styles'));
});
gulp.task('jshint', function() {
watchOrNot(sources.scripts)
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'))
});
gulp.task('browserify', function() {
watchOrNot(sources.browserify)
.pipe(browserify())
.pipe(concat('main.js'))
.pipe(gulp.dest(outDir + '/scripts/'))
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment