吞吐连续的任务作为流 [英] Gulp consecutive tasks as stream

查看:142
本文介绍了吞吐连续的任务作为流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我的任务分成两部分。首先是发展。没有魔法,只是基本的东西,使其工作。它快速和伟大。后者用于生产。速度很慢,我只想定期运行它进行测试,调试,优化和生产。因此,它们是两个独立的任务。

后者是生产任务,它依赖于前一个任务,但是,我想继续流,就好像后者的任务是对前者的补充。

  gulp.task('styles',function(){
返回gulp.src('src / sass / ** / *。scss')
.pipe(sass())
.pipe(autoprefixer())
.pipe(gulp.dest ('dist / css'));
});

gulp.task('styles-production',function(){
return runTaskAndUseStream('styles')
//继续样式任务结束
。管(uncss({
...
}))
.pipe(gulp.dest('dist / css'));
});

我希望没有记录 gulp.start ('task')方法会返回一个流,但不幸的是它不会。许多模块确实可以让你摆弄流,但是没有一个模块会以流的形式返回吞食任务。



什么?

  var gutil = require('gulp-util'); 

function production(task){
return(gutil.env.production?task:gutil.noop());

$ b $ gulp.task('styles',function(){
return gulp.src('src / sass / ** / *。scss')
.pipe(sass())
.pipe(autoprefixer())
.pipe(production(uncss({

})))
.pipe gulp.dest('dist / css'));
});

您需要的软件包: gulp-util noop任务和参数解析



使用 gulp样式--production

运行

(未经测试,但您明白了)

Basically, I have tasks split in two. The first is for development. There’s no magic, just basic stuff to make it work. It’s fast and great. The latter is for production. It’s slow, and I only want to run it periodically for testing, debugging, optimisation and production. Hence they are two separate tasks.

The latter, the task for production, does rely on the former task, however, I’d like to continue the stream, as if the latter task is an addition to the former.

gulp.task('styles', function() {
    return gulp.src('src/sass/**/*.scss')
        .pipe(sass())
        .pipe(autoprefixer())
        .pipe(gulp.dest('dist/css'));
});

gulp.task('styles-production', function() {
    return runTaskAndUseStream('styles')
         // Continue where the styles task ended
         .pipe(uncss({
             ...
         }))
         .pipe(gulp.dest('dist/css'));
});

I was hoping the undocumented gulp.start('task') method would return a stream, but unfortunately it doesn’t. Many modules does allow you to fiddle with streams, but none of them returns a gulp task as a stream.

What do?

解决方案

One thing that is (most likely) considered best practice would be incorporating the uncss task into your styles task, but running it only when certain flags are set:

var gutil = require('gulp-util');

function production(task) {
    return (gutil.env.production ? task : gutil.noop());
}

gulp.task('styles', function() {
    return gulp.src('src/sass/**/*.scss')
        .pipe(sass())
        .pipe(autoprefixer())
        .pipe(production(uncss({

        })))
        .pipe(gulp.dest('dist/css'));
});

Packages you need: gulp-util for the noop task, and argument parsing

run it with gulp styles --production

(untested, but you get the concept)

这篇关于吞吐连续的任务作为流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆