gulp:传递依赖任务返回流作为参数 [英] gulp: passing dependent task return stream as parameter
本文介绍了gulp:传递依赖任务返回流作为参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图创建两个gulp任务,并且我希望第二个任务能够获取第一个输出流并继续使用插件。
I'm trying to create two gulp tasks, and I'd like the second task to take the first one's output stream and keep applying plugins to it.
我可以将第一个任务的返回值传递给第二个任务吗?
Can I pass the first task's return value to the second task?
以下行不通:
// first task to be run
gulp.task('concat', function() {
// returning a value to signal this is sync
return
gulp.src(['./src/js/*.js'])
.pipe(concat('app.js'))
.pipe(gulp.dest('./src'));
};
// second task to be run
// adding dependency
gulp.task('minify', ['concat'], function(stream) {
// trying to get first task's return stream
// and continue applying more plugins on it
stream
.pipe(uglify())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('./dest'));
};
gulp.task('default', ['minify']);
有没有办法做到这一点?
Is there any way to do this?
推荐答案
您无法将流传递给其他任务。
,但您可以根据条件使用 gulp-if
模块跳过某些管道方法。
you can't pass stream to other task.
but you can use gulp-if
module to skip some piped method depending on conditions.
var shouldMinify = (0 <= process.argv.indexOf('--uglify'));
gulp.task('script', function() {
return gulp.src(['./src/js/*.js'])
.pipe(concat('app.js'))
.pipe(gulpif(shouldMinify, uglify())
.pipe(gulpif(shouldMinify, rename({suffix: '.min'}))
.pipe(gulp.dest('./dest'));
});
执行这样的任务来缩小
gulp script --minify
这篇关于gulp:传递依赖任务返回流作为参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文