I haven't been able to find any documentation of how one does this in gulp, not even sure one should do something like this:
var fileStream;
gulp.task('lint', ['glob'], function () {
var jshint = require('gulp-jshint');
fileStream.pipe(jshint())
.pipe(jshint.reporter('default'));
});
gulp.task('glob', function () {
fileStream = gulp.src([
'./js/**/*.js',
'!**/node_modules/**'
]);
});
Is this the best way to do something like this? Is there a nicer way to 'pass' the stream returned/created by 1 task into some other task(s) so that for something like this we don't duplicate the globbing while still making 'lint' & 'glob' distinct tasks. Is this even desirable in Gulp?
Thanks!
gulp.src
) and ends with a "sink" plugin (gulp.dest
, or like in your example, a reporter).So for your example:
var paths = {
scripts:[
'./js/**/*.js',
'!**/node_modules/**'
],
css: './css/**'
};
gulp.task('lint', function () {
var jshint = require('gulp-jshint');
var stream = gulp.src(paths.scripts)
.pipe(jshint())
.pipe(jshint.reporter('default'));
return stream;
});
gulp.task('cssmin', function () {
var stream = gulp.src(paths.css)
.pipe(cssmin())
.pipe(gulp.dest("..."));
return stream;
});
Gulp's task orchestrator (and soon a new one coming for Gulp 4) is dealing with task dependencies and their execution. Remember, those tasks can be async, so you don't want to share a stream that can be used by multiple consumers!
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