Everytime I run gulp, I see this message gulp.run() has been deprecated. Use task dependencies or gulp.watch task triggering instead.
Example code:
var watch = require('gulp-watch');
watch(['public/**/*.js','!public/**/*.min.js'],function(){
gulp.run('compressjs');
gulp.run('bs-reload');
});
How can I avoid using gulp.run()
with gulp-watch?
You shouldn't use run
. Here is an alternative (to address that part of your answer), but not what you need to do:
gulp
.start('default')
.once('task_stop', function(){
//do other stuff.
});
If you really must fire an ad hoc task, but can literally use run...You can use .start
with the task name, and also attach to the task_stop
handler to fire something when the task is complete. This is nice when writing tests for gulp tasks, but that's really it.
however in day to day gulp usage, this is an antipattern.
Normally, you build smaller tasks and composite them. This is the right way. See this:
var gulp = require('gulp'),
runSequence = require('run-sequence');
function a(){
//gulpstuff
}
function b(){
//gulpstuff
}
function d(callback){
runSequence('a', 'b', callback)
}
gulp
.task('a', a) // gulp a -runs a
.task('b', b) // gulp b runs b
.task('c', ['a', 'b']) //gulp c runs a and b at the same time
.task('d', d); //gulp d runs a, then b.
basically if c or d was a watch task, you'd achieve the same goal of firing the already registered smaller gulp tasks without .run
gulp.run()
was deprecated because people were using it as a crutch. You are using it as a crutch!
I'm not sure why you're using gulp-watch
, the built in gulp.watch
would be far more appropriate for what you're using it for. Have a look at the documentation for .watch: https://github.com/gulpjs/gulp/blob/master/docs/API.md#gulpwatchglob--opts-tasks-or-gulpwatchglob--opts-cb
Here's what you should have written. Please understand why you're using it instead of just copying it:
gulp.watch(['public/**/*.js','!public/**/*.min.js'], ['compressjs', 'bs-reload'])
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