吞吐连续的任务作为流 [英] Gulp consecutive tasks as stream
问题描述
后者是生产任务,它依赖于前一个任务,但是,我想继续流,就好像后者的任务是对前者的补充。
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屋!