Skip to content

Instantly share code, notes, and snippets.

@jsmithdev
Forked from webdesserts/Gulpfile.js
Last active December 13, 2018 01:18
Show Gist options
  • Save jsmithdev/eec359f71cf69fbe376f16cb6e9d3bd4 to your computer and use it in GitHub Desktop.
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).
// 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