gulp-nodemon
gulp-nodemon copied to clipboard
child_process.spawnSync restarts gulp
The change to having nodemon restart after other gulp tasks have run is pretty sweet, but with it came the restart of gulp on save of watched files as evidenced by this every save:
[15:18:19] Using gulpfile ~/Code/[project directory]/gulpfile.js
The project I'm working on is fairly large and am running a JSHint task every save of .js
files. This task takes ~6.5 seconds to complete so we use gulp-cached to cut down on that time so that every subsequent save is much faster on linting. In gulp-nodemon <2.0.0 gulp-cached worked wonderfully, but now with the restart of the gulp task on change the cache gets destroyed. Is there any way to get around restarting gulp task?
@jasonmerino can you use the .on('restart')
event that gets emitted? Sounds like for your purposes it'd work fine.
The problem still exists if I use the .on('restart')
event handler, plus the server restarts before the changes happen, which is fine for jshint, but if I need to use it to compile some .js
files or something it would require another restart of the server for the changes to take place in the browser.
Here's the log of what happens with the .on('restart', ['jshint'])
handler when I save a watched file twice:
$ gulp serve
[14:10:06] Using gulpfile ~/Code/[project-folder]/gulpfile.js
[14:10:06] Starting 'serve'...
[14:10:06] Finished 'serve' after 1.79 ms
[14:10:06] [nodemon] v1.3.7
[14:10:06] [nodemon] to restart at any time, enter `rs`
[14:10:06] [nodemon] watching: /Users/jasonmerino/Code/[project-folder]/src/config/**/* /Users/jasonmerino/Code/[project-folder]/src/app/**/* /Users/jasonmerino/Code/[project-folder]/src/lib/**/* /Users/jasonmerino/Code/[project-folder]/src/sass/**/*
[14:10:06] [nodemon] starting `node src/server.js`
HTTP server listening on 0.0.0.0:3000
[14:10:10] [nodemon] restarting due to changes...
[14:10:11] Using gulpfile ~/Code/[project-folder]/gulpfile.js
[14:10:11] Starting 'jshint'...
[14:10:18] Finished 'jshint' after 6.6 s
[14:10:18] [nodemon] starting `node src/server.js`
HTTP server listening on 0.0.0.0:3000
[14:10:22] [nodemon] restarting due to changes...
[14:10:23] Using gulpfile ~/Code/[project-folder]/gulpfile.js
[14:10:23] Starting 'jshint'...
[14:10:29] Finished 'jshint' after 6.45 s
[14:10:29] [nodemon] starting `node src/server.js`
HTTP server listening on 0.0.0.0:3000
Consider using event 'exit'
.on('exit', ['lint', 'test'])
@jasonmerino I haven't forgotten about this.
Gulp isn't 'restarting' every time, it's simply spawning a new gulp instance as a child of the parent process. So I'm not exactly sure what's wrong here, but I'll come back to this.
I've also just been bitten by this one.
I've just added a quick and dirty console.log('New cache:', name)
into the index.js
of gulp-cached, and every time gulp-nodemon spawns a new gulp instance it doesn't keep the state of it's parent
I'm using gulp-file cache
for this one, for future reference.
What we could do is add some feature to gulp-nodemon
and automatically forward cache info to the child process! So this is a feature request.