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

哈罗德

我想传递一个不需要编译的文件,也不需要将其保存到新位置进行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目录中保存一个临时文件时,所有文件(theme / ** / *。liquid)都将被上传。gulp-changed无效,因为任务运行时目标和源相同。

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

Ben

您可以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);
});

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章