I was dealing with the same problem, and the solution in my case was actually very simple. Two things.
npm install nodemon -g (or locally if you prefer)- run with cmd or create a script in the following packages:
"dev": "nodemon --watch gulpfile.js --exec gulp" - Just type
npm run dev
- viewing indicates the file to be monitored, --exec says that executing the next in line and gulp is your default task. Just pass an argument if you want a custom task.
Hope this helps.
EDIT: Make it a fantasy;) Now that the first part should achieve what you need, in my setup I needed to add a little more to make it a real user. I wanted to
- First open the page.
- Look for changes in gulpfile.js and restart gulp if any
- Gulp it should monitor files, rebuild and reboot
If you do only what I said in the first part, it will open the page every time. To fix this, create a gulp task that will open the page. Like this:
gulp.task('open', function(){ return gulp .src(config.buildDest + '/index.html') .pipe(plugins.open({ uri: config.url }));
Then in my main tasks I:
gulp.task('default', ['dev-open']); gulp.task('dev-open', function(done){ plugins.sequence('build', 'connect', 'open', 'watch', done); }); gulp.task('dev', function(done){ plugins.sequence('build', 'connect', 'watch', done); });
Then change your npm scripts to
"dev": "gulp open & nodemon --watch gulpfile.js --watch webpack.config.js --exec gulp dev"
Gives you exactly what you want. First open the page, and then just continue the live reboot. Btw for livereload I use the one that comes with the connection, which always uses the same port. Hope it works for you, enjoy!
Peter Kottas Jun 06 '16 at 10:10 2016-06-06 10:10
source share