it always rerun all gulp task when watch trigger server.run
zzswang opened this issue · 5 comments
it always rerun all gulp task when watch trigger server.run.
I use the sample gulpfile.js in the readme.
Also running into this. It's blocking me from using gulp-express, as I have other gulp tasks that deploy my app to production that should not be run. They are currently getting run when server.run
is called.
Any way I can help with this fix?
Same problem I encountered. Here is the workaround:
// start the server in an independent task:
gulp.task('express-run', function () {
server.run({
file: 'app.js'
});
});
// and then use this:
gulp.watch(['app.js', 'routes/**/*.js'], ['express-run']);
// instead of:
// gulp.watch(['app.js', 'routes/**/*.js'], [server.run]);
Merged the change, I assume this was fixed.
@gimm Unfortunately not. I still experience this issue (and another user as well: #18). cc @thiagomata
Note: I have performed npm update gulp-express
and manually checked that I have the latest version of your package.
I’m happy to report that I’ve managed to make it work correctly. Here is an excerpt of my gulpfile:
var gulp = require('gulp');
var server = require('gulp-express');
var livereload = require('gulp-livereload');
// etc.
gulp.task('server', function () {
server.run({ port: 35730 });
gulp.watch('source/styl/*.styl', ['build-css']);
gulp.watch(['app.js', 'routes/*.js'], function (e) {
server.run({ port: 35730 });
livereload.changed(e.path);
});
});
gulp.task('build-css', function () {
return gulp.src('source/styl/*.styl')
.pipe(stylus({ compress: false, 'include css': true }))
// other tasks
.pipe(gulp.dest('public/css/'))
.pipe(livereload());
});
I don’t know why switching from [server.run]
to function () { server.run() }
fixes the issue for me.
A note regarding my use of gulp-livereload: I’m using this plugin to manually handle refresh in the browser. I’m doing this because server.notify
cannot be nicely integrated into .watch()
arguments when there are other tasks listed (['build-css']
in my code). There is the workaround with using a callback function (described in the README of this repo) which I haven’t tried, but that code pattern does not seem optimal, so I’ve decided to run a custom livereload server using gulp-livereload. Notice how it can be easily hooked up to my "build-css" task by simply piping it at the end (.pipe(livereload())
). It would be great if server.notify
supported an analogous approach.