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

后端 未结 10 1256
感情败类
感情败类 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:31

    Forgive me for resurrecting an old question. The accepted answer does not address the issue of running tasks before setting the watches. The next answer uses gulp.start which is going away. The third answer points out that regular functions should be used but the example seems strange. I did some searching but did not find a simple example.

    Here is my solution. The idea is to define regular js functions then register them as tasks. The functions can then be called directly if needed or from within a watch.

    var 
      gulp     = require('gulp'),
      concat   = require('gulp-concat'),
      markdown = require('gulp-showdown')
    ;
    var scriptFiles   = [ 'ang/app.js' ];
    var markdownFiles = [ 'content/articles/*.md'];
    
    var watchTask = function() 
    {
      buildTask();
    
      gulp.watch(scriptFiles,  ['scripts' ]);
      gulp.watch(markdownFiles,['markdown']);
    };
    gulp.task('watch',watchTask);
    
    var buildTask = function()
    {
      scriptsTask();
      markdownTask();
    };
    gulp.task('build',buildTask);
    
    var markdownTask = function() 
    {
      gulp.src(markdownFiles)
        .pipe(markdown())
        .pipe(gulp.dest('web/articles'));
    };
    gulp.task('markdown',markdownTask);
    
    var scriptsTask = function() 
    {
      gulp.src(scriptFiles)
        .pipe(concat('app.js'))
        .pipe(gulp.dest('web/js'));
    
      gulp.src(
        [
          'bower_components/angular/angular.min.js',
          'bower_components/angular-route/angular-route.min.js'
        ])
        .pipe(concat('vendor.js'))
        .pipe(gulp.dest('web/js'));
    
      gulp.src(
        [
          'bower_components/angular/angular.min.js.map',
          'bower_components/angular-route/angular-route.min.js.map'
        ])
        .pipe(gulp.dest('web/js'));
    };
    gulp.task('scripts', scriptsTask);
    

    I am new to gulp. Please let me know if I have overlooked something obvious.

提交回复
热议问题