Gulp run alternative

后端 未结 3 1935
旧时难觅i
旧时难觅i 2021-01-13 14:31

Everytime I run gulp, I see this message gulp.run() has been deprecated. Use task dependencies or gulp.watch task triggering instead.

Example code:

3条回答
  •  野的像风
    2021-01-13 15:18

    You shouldn't use run. Here is an alternative (to address that part of your answer), but not what you need to do:

    gulp
        .start('default')
        .once('task_stop', function(){
            //do other stuff.
         });
    

    If you really must fire an ad hoc task, but can literally use run...You can use .start with the task name, and also attach to the task_stop handler to fire something when the task is complete. This is nice when writing tests for gulp tasks, but that's really it.

    however in day to day gulp usage, this is an antipattern.

    Normally, you build smaller tasks and composite them. This is the right way. See this:

    var gulp = require('gulp'),
        runSequence = require('run-sequence');
    
    function a(){
      //gulpstuff
    } 
    function b(){
      //gulpstuff
    }
    
    function d(callback){
      runSequence('a', 'b', callback)
    }
    
    gulp
        .task('a', a) // gulp a -runs a
        .task('b', b) // gulp b runs b
        .task('c', ['a', 'b']) //gulp c runs a and b at the same time
        .task('d', d); //gulp d runs a, then b.
    

    basically if c or d was a watch task, you'd achieve the same goal of firing the already registered smaller gulp tasks without .run

提交回复
热议问题