gulp:传递依赖任务返回流作为参数

编程入门 行业动态 更新时间:2024-10-27 08:37:32
本文介绍了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:传递依赖任务返回流作为参数

本文发布于:2023-11-06 07:41:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1563100.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:参数   gulp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!