Reputation: 13843
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?
Upvotes: 3
Views: 268
Reputation: 7574
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)
Upvotes: 3