gulp.series() doesn't run tasks

泪湿孤枕 提交于 2019-12-10 18:06:03

问题


I can't figure out why gulp.series() is not firing in my callback function.

I'm trying to grab a string from a user input with gulp-prompt and invoke a build and deployment function with gulp.series(). My tasks within gulp.series() don't fire at all.

gulp.task('test', function(){
  const prompt = require('gulp-prompt');
  return gulp.src('test.js')
    .pipe(prompt.prompt({
        type: 'checkbox',
        name: 'env',
        message: 'which environment do you want to deploy to?',
        choices: ['qa','prod']
    },function(res){
      //console.dir(res.env);
        var env = res.env;
        console.log(env);
        console.log('hi');
        gulp.series('clean', 'patternlab:build', 'tag-version', deployWeb.bind(this, env), function(done){
          done();
        });
    }));
});

回答1:


Calling gulp.series('task1', 'task2') does not run task1 and task2. All it does is return a new function. Only once you call that function are the tasks actually executed.

That means in your case you need to do the following:

var runTasks = gulp.series('clean', 'patternlab:build',
                           'tag-version', deployWeb.bind(this, env));
runTasks();

The whole function(done){ done(); } part that you had in your code doesn't really make much sense and isn't needed for gulp.series().




回答2:


Sven Schoenung's answer is correct.

If you don't want to add a new variable, just make it a self-calling JS function like,

gulp.series('clean', 'patternlab:build', 'tag-version', deployWeb.bind(this, env))();


来源:https://stackoverflow.com/questions/39902010/gulp-series-doesnt-run-tasks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!