H
H
Homsa Toft2016-02-28 09:39:45
Node.js
Homsa Toft, 2016-02-28 09:39:45

How to terminate the task ahead of time, according to the condition, without killing watch at the same time?

Actually, the idea is to have both the dev and production versions in different folders without creating tasks.

gulp.task('jade', function () {
  return gulp.src(config.src.jade)
  .pipe(plumber())
  .pipe(jade({
    pretty: true // Комментарии и отформатированный код.
  }))
  .pipe(gulp.dest(config.dev.html))
  .pipe(gulpif(!isDevelopment, htmlmin({
    collapseWhitespace: true,
    removeComments: true
  }), /* Здесь надо выйти!? */))
  .pipe(gulp.dest(config.prod.html)) 
})

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
fayster, 2016-02-28
@kostein

Alternatively, you can do this:

const through2 = require('through2').obj;

gulp.task('jade', function (callback) {
  return gulp.src(config.src.jade)
  .pipe(plumber())
  .pipe(jade({
    pretty: true // Комментарии и отформатированный код.
  }))
  .pipe(gulp.dest(config.dev.html))
  .pipe(gulpif(!isDevelopment, htmlmin({
    collapseWhitespace: true,
    removeComments: true
  })
  .pipe(through2((file, enc, cb) => {
    if (isDevelopment) { // задаем условие
     callback(); // выходим из таска
    } else {
     cb(null, file); // передаем файлы дальше в поток
    }
  }))
  .pipe(gulp.dest(config.prod.html)) 
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question