-
-
Save jsmithdev/eec359f71cf69fbe376f16cb6e9d3bd4 to your computer and use it in GitHub Desktop.
Revised for Gulp v4: Automatically reload your node.js app on file change with Gulp (https://github.com/wearefractal/gulp).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// jshint esversion: 6, asi: true, laxcomma: true | |
const gulp = require('gulp') | |
, spawn = require('child_process').spawn | |
, killer = node => node ? node.kill() : null | |
, config = { | |
init: ['index.js'], | |
watch: ['*.js'] | |
} | |
; | |
let node | |
const server = () => { | |
killer(node) | |
node = spawn('node', config.init, {stdio: 'inherit'}) | |
node.on('close', code => { | |
if (code === 8) { | |
gulp.log('Error detected, waiting for changes...') | |
} | |
}) | |
} | |
const task = cb => { | |
gulp.watch(config.watch, cb => server(cb())) | |
server() | |
cb() | |
} | |
exports.default = task |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment