Как выйти из задачи с gulp-if - PullRequest
       47

Как выйти из задачи с gulp-if

0 голосов
/ 08 октября 2019

У меня есть задание gulp 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));
}

1 Ответ

0 голосов
/ 08 октября 2019

См. 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?")));
})
...