Skip to content

Instantly share code, notes, and snippets.

@Jeff2Ma
Created December 29, 2016 11:16
Show Gist options
  • Save Jeff2Ma/a20c652cb56c5411bad5f5879b7c4098 to your computer and use it in GitHub Desktop.
Save Jeff2Ma/a20c652cb56c5411bad5f5879b7c4098 to your computer and use it in GitHub Desktop.
Gulp reload on gulpfile.js change
// Gulp restart when gulpfile is changed
var spawn = require('child_process').spawn;
gulp.task('gulp-autoreload', function() {
// Store current process if any
var p;
gulp.watch('gulpfile.js', spawnChildren);
// Comment the line below if you start your server by yourslef anywhere else
spawnChildren();
function spawnChildren(e) {
if(p) {
p.kill();
}
p = spawn('gulp', ['build'], {stdio: 'inherit'});
}
});
gulp.task('build', function() {
// Your stuff here with build
// Moreover, it's a good idea to have livereload if necessary
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment