0
votes

I am wondering how to pass a single file to gulp task.
I don't want to filter entire collection of files and also don't want to waste resources to parse all files from collection by task.
So I thought the best way is to pass a single changed file from gulp.watch() to gulp task, but found no working solution.

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
    })
});

Is there a way to run gulp tasks like that? I've tried with function instead of task but it don't works.

1

1 Answers

0
votes

It sounds like you want something like gulp-cached or gulp-changed to only pass through changed files. So:

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'])
});