2015-07-18 82 views
3

我正在嘗試收集3個需要在1中進行調試的任務。當然,因爲gulp的性質是異步的,所以我遇到了問題。所以我搜索並找到了一個使用run-sequence模塊來解決這個問題的解決方案。我嘗試了下面的代碼,但它似乎沒有按預期工作。它不是同步的。 這是我的嘗試。任何想法傢伙?我不想運行所有這三個命令來完成所有任務。我怎樣才能做到這一點?Gulp同步任務問題

var gulp = require('gulp'), 
    useref = require('gulp-useref'), 
    gulpif = require('gulp-if'), 
    debug = require('gulp-debug'), 
    rename = require("gulp-rename"),  
    replace = require('gulp-replace'), 
    runSequence = require('run-sequence'), 
    path = '../dotNet/VolleyManagement.UI'; 

gulp.task('debug', function() { 
    gulp.src('client/*.html') 
     .pipe(debug()) 
     .pipe(gulp.dest(path + '/Areas/WebAPI/Views/Shared')); 
}); 

gulp.task('rename', function() {  
    gulp.src(path + '/Areas/WebAPI/Views/Shared/index.html') 
     .pipe(rename('/Areas/WebAPI/Views/Shared/_Layout.cshtml')) 
     .pipe(gulp.dest(path));   

    gulp.src(path + '/Areas/WebAPI/Views/Shared/index.html', {read: false}) 
     .pipe(clean({force: true})); 
}); 

gulp.task('final', function(){ 
    gulp.src([path + '/Areas/WebAPI/Views/Shared/_Layout.cshtml']) 
     .pipe(replace('href="', 'href="~/Content')) 
     .pipe(replace('src="', 'src="~/Scripts')) 
     .pipe(gulp.dest(path + '/Areas/WebAPI/Views/Shared/')); 
}); 

gulp.task('debugAll', runSequence('debug', 'rename', 'final')); 

回答

1

我想你並沒有定義'debugAll'任務的權利。試試這樣:

gulp.task('debugAll', function() { 
    runSequence('debug', 'rename', 'final'); 
}); 

,你也需要返回這些任務流,只是在gulp.src前加上「迴歸」爲他們每個人:調試,重命名,最終的決定。這裏是「調試」任務的例子:

gulp.task('debug', function() { 
    return gulp.src('client/*.html') 
     .pipe(debug()) 
     .pipe(gulp.dest(path + '/Areas/WebAPI/Views/Shared')); 
}); 

兩個項目都在文檔中提到:https://www.npmjs.com/package/run-sequence

+0

是的,我的不好。但我現在嘗試了正確的語法,並且無論如何都不能一個接一個地工作...... – Ivan

+1

在開始時沒有看到它,但實際上您需要返回這些任務的流。只需在gulp.src前面爲每個任務添加'return'(調試,重命名和最終)。同樣的問題是上面的@ramesh答案 - 你不返回流。這也在文檔中提到:https://www.npmjs.com/package/run-sequence –

+0

這正是我錯過的!謝謝你指出,現在所有的工作都很好:) P.S.你可以編輯你的答案與上面的信息,所以我可以標記你的答案被接受? – Ivan

3

在gulp中,你可以真正設置依賴任務。試試這個:

gulp.task('debug', function() { 
    //run debug task 
}); 

gulp.task('rename',['debug'], function() {  
    //run rename once debug is done 
}); 
+1

我試過了,但事情是,它是異步運行的太...「調試」任務完成'重命名'後 – Ivan

+0

看到接受的答案。另見➝http://stackoverflow.com/a/22826429/444255 –