【问题标题】:Gulp-js pass only saved file on to taskGulp-js 仅将保存的文件传递给任务
【发布时间】:2014-09-05 15:03:04
【问题描述】:

我想将一个不需要编译或不需要保存到新位置的已保存文件传递给 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 不起作用,因为在任务运行时目标和源是相同的。

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

【问题讨论】:

    标签: gulp gulp-watch


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2015-04-16
      • 1970-01-01
      • 2019-03-10
      • 2023-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多