Skip to content

Instantly share code, notes, and snippets.

@pibby
Created Jul 5, 2015
Embed
What would you like to do?
Livereload via Gulp and Jekyll build
var gulp = require('gulp');
var cp = require('child_process');
var shell = require('gulp-shell');
var express = require('express');
var livereload = require('gulp-livereload');
gulp.task('default', ['watch']);
// Run static file server
gulp.task('serve', function () {
var server = express();
server.use(express.static('_site'));
server.listen(4000);
});
// Watch for changed files
gulp.task('watch', ['jekyll', 'serve'], function () {
// Create LiveReload server
livereload.listen({ port: 35729, basePath: '_site' });
// Watch files, reload on change
gulp.watch('_site/**').on('change', function (file) {
livereload.changed(file.path);
});
gulp.watch(['./*.html', '_layouts/*.haml', '_includes/*.haml', '**/*.md', '_sass/**/*.scss', './images/**/*', '!_site/**', '!_site/**/*'], ['jekyll']);
});
// Compile pages with Jekyll
gulp.task('jekyll', function () {
return cp.spawn('jekyll', ['build']);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment