2015-12-22 79 views
0

我有一個包含幾個不同任務的gulp文件。當我想製作一個生產版本時,我運行,gulp.task('build', ['styles', 'uglify', 'copyScripts', 'copyImgs', 'copyFonts', 'compress']);。我遇到的問題是我需要任務compress在所有其他人完成後運行。Gulp在所有其他任務之後創建zip文件

+0

也許複製http://stackoverflow.com/questions/34285269/task-dependency-in-gulp/34285442#34285442 – MarcoL

+0

的那會不會真的在工作我的情況,因爲我不希望壓縮總是有其他任務需要運行。如果需要,我希望能夠隨意運行gulp compress。 –

+0

將壓縮任務內容移動到一個單獨的函數中,然後調用此函數作爲「構建」任務的回調 – MarcoL

回答

1

你可以嘗試以下方法:

function compressFn(){ 
    // write the code to compress here 
} 

// For backward compatibility with other tasks 
gulp.task('compress', compressFn); 

// It performs first all the tasks in the array THEN it calls compressFn 
gulp.task('build', ['styles', 'uglify', 'copyScripts', 'copyImgs', 'copyFonts'], compressFn); 
相關問題