2016-10-23 58 views
0

我想知道如何傳遞一個文件來吞噬任務。
我不想過濾整個文件的集合,也不想浪費資源來解析任務收集的所有文件。
所以我認爲最好的辦法是從gulp.watch()傳遞一個更改的文件來吞嚥任務,但沒有找到可行的解決方案。
從觀察者的參數運行吞噬任務

gulp.task('html', function(file) { 
    return gulp.src(file) 
     .pipe(fileInclude(fileIncludeConf)) 
     .pipe(gulp.dest(paths.dest.templates)); 
}); 

gulp.task('watch', function() { 
    gulp.watch(path.src.templates).on('change', function(file) { 
     // gulp run 'html' task with 'file' as src 
    }) 
}); 

有沒有辦法像這樣運行吞嚥任務?我嘗試過使用函數而不是任務,但它不起作用。

回答

0

這聽起來像你想要的東西像gulp-cachedgulp-changed只能通過更改的文件。所以:

var cache = require('gulp-cached'); 

gulp.task('html', function(file) { 
    return gulp.src(file) 
     .pipe(cache("only working on changed files here") 
     .pipe(fileInclude(fileIncludeConf)) 
     .pipe(gulp.dest(paths.dest.templates)); 
}); 

gulp.task('watch', function() { 
    gulp.watch(path.src.templates, ['html']) 
});