Skip to content

Instantly share code, notes, and snippets.

@ericdouglas
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save ericdouglas/8855147 to your computer and use it in GitHub Desktop.

Select an option

Save ericdouglas/8855147 to your computer and use it in GitHub Desktop.
test gulpfile
var
gulp = require('gulp'),
jade = require('gulp-jade'),
stylus = require('gulp-stylus'),
jshint = require('gulp-jshint'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
rename = require('gulp-rename');
gulp.task('jade', function () {
gulp.src('./*.jade')
.pipe(jade({
pretty:true
}
))
.pipe(gulp.dest('./public'));
});
gulp.task('stylus', function () {
gulp.src('./*.styl')
.pipe(stylus())
.pipe(gulp.dest('./public/css'));
});
gulp.task('lint', function () {
return gulp.src('js/*.js')
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
// Concatenate and minify .js
gulp.task('scripts', function () {
return gulp.src('js/*.js')
.pipe(concat('main.js'))
.pipe(gulp.dest('public/js'))
.pipe(rename('main.min.js'))
.pipe(uglify())
.pipe(gulp.dest('public/js'));
});
var EXPRESS_PORT = 4000;
var EXPRESS_ROOT = __dirname;
var LIVERELOAD_PORT = 35729;
function startExpress() {
var express = require('express');
var app = express();
app.use(require('connect-livereload')());
app.use(express.static(EXPRESS_ROOT));
app.listen(EXPRESS_PORT);
}
var lr;
function startLivereload() {
lr = require('tiny-lr')();
lr.listen(LIVERELOAD_PORT);
}
function startPlugins () {
gulp.run('jade');
gulp.run('stylus');
gulp.run('lint');
gulp.run('scripts');
}
function notifyLivereload(event) {
gulp.src(event.path, {read: false})
.pipe(require('gulp-livereload')(lr));
}
gulp.task('default', function () {
startExpress();
startLivereload();
startPlugins();
gulp.watch('*.jade', ['jade']);
gulp.watch(['public/*.html'], notifyLivereload);
gulp.watch('*.styl', ['stylus']);
gulp.watch(['public/css/*.css'], notifyLivereload);
gulp.watch('js/*.js', ['lint', 'scripts']);
gulp.watch(['public/js/*.js'], notifyLivereload);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment