Gulp-js只将保存的文件传递给任务

时间:2014-09-05 15:03:05

标签: gulp gulp-watch

我想传递一个不需要编译的保存文件,或者不需要将其保存到新位置以进行gulp-tap,这样我就可以在其上运行外部脚本。

现在我看一个完整的目录,每次保存时我都会上传整个目录:

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目录中保存液体文件时,都会上传所有文件(主题/ ** / * .squid)。 gulp-changed在任务运行目的地和源相同时不起作用。

仅上传更改后的文件的最佳方法是什么?

1 个答案:

答案 0 :(得分: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);
});