Skip to content

Instantly share code, notes, and snippets.

@joemaller
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joemaller/87723dd885d81da78a8c to your computer and use it in GitHub Desktop.
Save joemaller/87723dd885d81da78a8c to your computer and use it in GitHub Desktop.
A proof-of-concept gulpfile that reloads itself onchange. Not especially stable and leaves an orphan gulp process, but useful for quickly iterating a gulpfile.
'use strict';
var gulp = require('gulp');
var spawn = require('child_process').spawn;
/**
* gulpfile-reload auto-reloads this gulpfile, called from 'watch'
* This leaves an orphaned gulp process running after `gulp watch` exits
*/
gulp.task('gulpfile-reload', function() {
spawn('gulp', ['watch'], {stdio: 'inherit'});
process.exit();
});
gulp.task('watch', function() {
gulp.watch('gulpfile.js', ['gulpfile-reload']);
});
{
"name": "gulpfile-reload",
"version": "0.0.0",
"private": true,
"author": "Joe Maller <joe@joemaller.com>",
"license": "MIT",
"devDependencies": {
"gulp": "^3.8.*"
}
}
@Edo78
Copy link

Edo78 commented Jun 29, 2015

if you don't take care of previous spawned child you'll keep adding new processes ...

try something like

if(p) { p.kill(); }
p = spawn(...);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment