Gulpjs combine two tasks into a single task

后端 未结 11 1163
攒了一身酷
攒了一身酷 2020-12-24 01:56

I currently have two tasks, that both compile sass files. I would still like to concat the two directories into separate files but it seems that it would be more maintainabl

11条回答
  •  旧时难觅i
    2020-12-24 02:25

    Solution 1:

    gulp.task('sass', function() {
      gulp.start('bootstrap-sass', 'site-sass');
    })
    

    gulp.start runs tasks in parallel. And it's asynchronous, which means 'bootstrap-sass' may be finished before 'site-sass'. But it's not recommended because

    gulp.start is undocumented on purpose because it can lead to complicated build files and we don't want people using it

    see https://github.com/gulpjs/gulp/issues/426

    Solution 2:

    var runSequence = require('run-sequence');
    gulp.task('sass', function (cb) {
      runSequence(['bootstrap-sass', 'site-sass'], cb);
    });
    

    run-sequence is a gulp plugin.

    Runs a sequence of gulp tasks in the specified order. This function is designed to solve the situation where you have defined run-order, but choose not to or cannot use dependencies.

    runSequence(['bootstrap-sass', 'site-sass'], cb);
    

    This line runs 'boostrap-sass' and 'site-sass' in parallel.If you want to run tasks serially, you can

    runSequence('bootstrap-sass', 'site-sass', cb);
    

提交回复
热议问题