Setting up auto-reload for development work

This commit is contained in:
Jesper Hess 2016-03-31 16:17:50 +02:00
parent 211a0201aa
commit 95bf511043
2 changed files with 54 additions and 0 deletions

48
gulpfile.js Normal file
View File

@ -0,0 +1,48 @@
var gulp = require('gulp');
var browserSync = require('browser-sync');
var cp = require('child_process');
var messages = {
jekyllBuild: '<span style="color: grey">Running:</span> $ jekyll build'
};
/**
* Build the Jekyll Site
*/
gulp.task('jekyll-build', function (done) {
browserSync.notify(messages.jekyllBuild);
return cp.spawn('jekyll', ['build'], {stdio: 'inherit'})
.on('close', done);
});
/**
* Rebuild Jekyll & do page reload
*/
gulp.task('jekyll-rebuild', ['jekyll-build'], function () {
browserSync.reload();
});
/**
* Wait for jekyll-build, then launch the Server
*/
gulp.task('browser-sync', ['jekyll-build'], function() {
browserSync({
server: {
baseDir: '_site'
}
});
});
/**
* Watch html/md files, run jekyll & reload BrowserSync
* if you add folder for pages, collection or datas, add them to this list
*/
gulp.task('watch', function () {
gulp.watch(['./*', '_layouts/*', '_includes/*', '_posts/*', '_sass/*', 'css/*'], ['jekyll-rebuild']);
});
/**
* Default task, running just `gulp` will compile the sass,
* compile the jekyll site, launch BrowserSync & watch files.
*/
gulp.task('default', ['browser-sync', 'watch']);

6
package.json Normal file
View File

@ -0,0 +1,6 @@
{
"devDependencies": {
"browser-sync": "^2.2.0",
"gulp": "^3.7"
}
}