Skip to content

Instantly share code, notes, and snippets.

@poksme
Created February 2, 2016 03:50
Show Gist options
  • Save poksme/cf40f31b969edc3b68bd to your computer and use it in GitHub Desktop.
Save poksme/cf40f31b969edc3b68bd to your computer and use it in GitHub Desktop.
Create static files from Jade, Markdown & Less then serve them and livereload via a Gulp workflow
/* global __filename */
var gulp = require('gulp');
var jade = require('gulp-jade');
var less = require('gulp-less');
var serve = require('gulp-serve');
var open = require('gulp-open');
var livereload = require('gulp-livereload');
gulp.task('build-templates', function() {
var locals = {};
return gulp.src('./templates/**/*.jade')
.pipe(jade({
locals: locals
}))
.pipe(gulp.dest('./public/'))
.pipe(livereload());
});
gulp.task('build-styles', function () {
return gulp.src('./styles/**/*.less')
.pipe(less({}))
.pipe(gulp.dest('./public/stylesheets'));
});
gulp.task('serve', serve('./public/'));
gulp.task('open', function () {
return gulp.src(__filename)
.pipe(open({uri: 'http://localhost:3000'}));
});
gulp.task('init-watch', function () {
return livereload.listen({ basePath: 'public' });
});
gulp.task('watch-styles', ['init-watch'], function () {
return gulp.watch('styles/**/*.less', ['build-styles']);
});
gulp.task('watch-templates', ['init-watch'], function () {
return gulp.watch('templates/**/*.jade', ['build-templates']);
});
gulp.task('watch-content', ['init-watch'], function () {
return gulp.watch('content/**/*.md', ['build-templates']);
});
gulp.task('build', ['build-templates', 'build-styles']);
gulp.task('watch', ['watch-templates', 'watch-styles', 'watch-content']);
gulp.task('default', ['build', 'serve', 'open', 'watch']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment