我有一个处理图像的任务4。首先,它将它们最小化,如果满足条件,则应将SVG转换为PHP局部函数。如果不满足,我该如何实现这种条件并停止任务。
function processImages() {
return src(src)
.pipe(
imagemin([
imagemin.gifsicle({
interlaced: true,
}),
imagemin.jpegtran({
progressive: true,
}),
imagemin.optipng({
optimizationLevel: 3,
}),
imagemin.svgo({
plugins: [
{
removeViewBox: false,
},
{
cleanupIDs: false,
},
],
}),
]),
)
.pipe(dest(dest))
// STOP AFTER THIS STEP IF CONDITION IS NOT MET
.pipe(gulpif(!shouldCreatePartials(), exit()))
.pipe(filter(file => /svg$/.test(file.path)))
.pipe(
rename({
extname: '.php',
}),
)
.pipe(dest(partialsDest));
}
请参阅gulp-fail-看起来是与gulp-if一起使用的。
var fail = require('gulp-fail');
var gulpIf = require('gulp-if');
var condition = true;
// Will fail with the given message shown as the reason.
gulp.task('mytask', function() {
return gulp.src('**/*.js')
.pipe(gulpIf(condition, fail("It failed cause I told it to! ...Hooray?")));
})