Skip to content

Instantly share code, notes, and snippets.

@alur222
Created August 7, 2018 04:22
Show Gist options
  • Save alur222/487deacafb1b22184649311a5d4ec039 to your computer and use it in GitHub Desktop.
Save alur222/487deacafb1b22184649311a5d4ec039 to your computer and use it in GitHub Desktop.
Sample gulp file for node js development with auto reload
const gulp = require('gulp');
const spawn = require('child_process').spawn;
let node;
function server() {
if (node) {
node.kill();
}
node = spawn('npm', ['run', 'runserver'], {stdio: 'inherit'});
node.on('close', function (code) {
if (code === 8) {
gulp.log('Error detected, waiting for changes...');
}
});
}
gulp.task('server', function() {
server();
});
gulp.task('watch-server', function() {
});
const watcher = gulp.watch(['./backend/**/*.js', './backend.js']);
watcher.on('change', function() {
console.log('server files modified')
server();
})
gulp.task('default', gulp.series('server', 'watch-server'));
// clean up if an error goes unhandled.
process.on('exit', function() {
if (node) {
node.kill();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment