【问题标题】:runSequence is not working with gulp?runSequence 不适用于 gulp?
【发布时间】:2015-09-16 22:14:46
【问题描述】:

runsequence 是不是下面的代码不能正常工作?

var gulp = require('gulp');
var del = require('del');
var browserify = require('gulp-browserify');
var concat = require('gulp-concat');
var runSequence = require('run-sequence');
var nodemon = require('gulp-nodemon');

gulp.task('clean', function(cb) {
  console.log('YOLO1');
  del(['build/*'], cb);
});

gulp.task('copy', function() {
 console.log('YOLO2')
 return gulp.src('client/www/index.html')
    .pipe(gulp.dest('build'));
});

gulp.task('browserify', function() {
  console.log('YOLO3')
  return gulp.src('client/index.js')
    .pipe(browserify({transform: 'reactify'}))
    .pipe(concat('app.js'))
    .pipe(gulp.dest('build'));
});

gulp.task('build', function(cb) {
  console.log('YOLO4')
  runSequence('clean', 'browserify', 'copy', cb);
});

gulp.task('default', ['build'], function() {
  gulp.watch('client/*/*', ['build']);
  nodemon({ script: './bin/www', ignore: ['gulpfile.js', 'build', 'client', 'dist'] });
});

电流输出:

YOLO4,
YOLO1

期望的输出:

 YOLO4,
 YOLO1,
 YOLO3,
 YOLO2

我不确定为什么 runSequence 只执行第一个任务而无法执行其余任务?有什么想法吗?

【问题讨论】:

    标签: javascript reactjs gulp


    【解决方案1】:

    del 不接受回调,而是同步返回:(参见https://github.com/gulpjs/gulp/blob/master/docs/recipes/delete-files-folder.md 中的第一个示例)

    gulp.task('clean', function() {
      console.log('YOLO1');
      return del(['build/*']);
    });
    

    【讨论】:

    • 这个答案需要裱起来贴在墙上。他们最近更改了del 行为(使用承诺,不再有回调),因此必须更新很多任务。
    猜你喜欢
    • 2016-12-24
    • 2017-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多