gulp.run is deprecated. How do I compose tasks?

后端 未结 10 1206
感情败类
感情败类 2020-12-22 18:57

Here is a composed task I don\'t know how to replace it with task dependencies.

...
gulp.task(\'watch\', function () {
 var server = function(){
  gulp.run(\         


        
相关标签:
10条回答
  • 2020-12-22 19:39

    Or you can do like this:

    gulp.start('task1', 'task2');
    
    0 讨论(0)
  • 2020-12-22 19:39

    source: https://github.com/gulpjs/gulp/issues/755

    gulp.start() was never meant to be a public api nor used. And as stated above in comments, the task management is being replaced in the next release....so gulp.start() will be breaking.

    The true intention of the gulp design is to make regular Javascript functions, and only make the task for calling them.

    Example:

    function getJsFiles() {
        var sourcePaths = [
            './app/scripts/**/*.js',
            '!./app/scripts/**/*.spec.js',
            '!./app/scripts/app.js'
        ];
    
        var sources = gulp.src(sourcePaths, { read: false }).pipe(angularFilesort());
    
        return gulp.src('./app/index.html')
            .pipe(injector(sources, { ignorePath: 'app', addRootSlash: false }))
            .pipe(gulp.dest('./app'));
    }  
    

    gulp.task('js', function () {
        jsStream = getJsFiles();
    });
    
    0 讨论(0)
  • 2020-12-22 19:44

    In Gulp 4 the only thing that seems to be working for me is:

    gulp.task('watch', function() {
        gulp.watch(['my-files/**/*'], gulp.series('my-func'));
    });
    
    gulp.task('my-func', function() {
        return gulp.src('[...]').pipe(gulp.dest('...'));
    });
    
    0 讨论(0)
  • 2020-12-22 19:53

    As @dman mentions that, gulp.start will be discarded in the next version. Also it can be seen in this issue of gulp.

    And in the comments of the answer of @Pavel Evstigneev, @joemaller mentions that we can use run-sequence in this scenario.

    But please note that, the author of run-sequence says :

    This is intended to be a temporary solution until the release of gulp 4.0 which has support for defining task dependencies in series or in parallel.

    Be aware that this solution is a hack, and may stop working with a future update to gulp.

    So, before gulp 4.0, we can use run-sequence, after 4.0, we can just use gulp.

    0 讨论(0)
提交回复
热议问题