I have the following code in my gulpfile
gulp.task('scripts', function () {
gulp.src(paths.browserify)
.pipe(browserify())
.pipe(gulp.dest('./build/js'))
.pipe(refresh(server));
});
gulp.task('lint', function () {
gulp.src(paths.js)
.pipe(jshint())
.pipe(jshint.reporter(stylish));
});
gulp.task('nodemon', function () {
nodemon({
script: 'app.js'
});
});
I need to run the scripts and lint tasks when Nodemon restarts.I have the following
gulp.task('nodemon', function () {
nodemon({
script: 'app.js'
}).on('restart', function () {
gulp.run(['scripts', 'lint']);
});
});
Gulp.run() is now deprecated, so how would I achieve the above using gulp and best practices?
gulp-nodemon documentation states that you can do it directly, passing an array of tasks to execute:
nodemon({script: 'app.js'}).on('restart', ['scripts', 'lint']);
See doc here
UPDATE, as the author of gulp-nodemon uses run as well:
Idea #1, use functions:
var browserifier = function () {
gulp.src(paths.browserify)
.pipe(browserify())
.pipe(gulp.dest('./build/js'))
.pipe(refresh(server));
});
gulp.task('scripts', browserifier);
var linter = function () {
gulp.src(paths.js)
.pipe(jshint())
.pipe(jshint.reporter(stylish));
});
gulp.task('lint', linter);
nodemon({script: 'app.js'}).on('restart', function(){
linter();
browserifier();
});
If you can, use Mangled Deutz's suggestion about using functions. That's the best, most guaranteed way to make sure this works now and going forward.
However, functions won't help if you need to run dependent tasks or a series of tasks. I wrote run-sequence to fix this. It doesn't rely on gulp.run
, and it's able to run a bunch of tasks in order.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With