2014-09-05 57 views
0

我想傳遞一個保存的文件,該文件不需要編譯或不需要保存到新的位置以吞噬點擊,這樣我就可以運行一個外部腳本它。gulp-js只將保存的文件傳遞給任務

現在我看一個完整的目錄,並在每次保存我上傳整個目錄:

gulp.task('shopify_theme',function(){ 
gulp.src('./theme/**/*.liquid') 
    .pipe(tap(function(file){ 
      upload(file); 
    })); 
}) 

這是上傳部(主題是上傳資產shopify的應用程序)

var upload = function(file){ 
var splitPath = file.path.split('theme/').pop(); 
run('theme upload ' + splitPath, { cwd: 'theme' }).exec(); 
}; 

每次我將一個液體文件保存在/ theme目錄中時,所有文件(theme/**/*。liquid)都會上傳。在任務運行時目的地和源地址相同時,gulp-changed不起作用。

什麼是隻上傳更改文件的最佳方式?

回答

0

您可以使用gulp.watch要監視更改到單個文件:

var upload = function(filePath){ 
    var splitPath = filePath.split('theme/').pop(); 
    run('theme upload ' + splitPath, { cwd: 'theme' }).exec(); 
}; 

gulp.watch('./theme/**/*.liquid', function(evnt) { 
    upload(evnt.path); 
}); 
+0

謝謝!這很好! :) – Harold 2014-09-07 00:02:03