gulp-chord-cache

1.0.2 • Public • Published

gulp-chord-cache

Cache files in gulp pipe.

Why gulp-chord-cache

Normally in gulp watch tasks, if one single file changed every watched file will be handled in a triggered task.

For example, compiling all files is unnecessary and inefficient because only one file is changed in most cases.

gulp-chord-cache will filter unchanged files and cache all handled files in formmer flows, the more files you are dealing with, the faster flows using gulp-chord-cache could be.

How it works

gulp-chord-cache caches all handled file contents in memory, when task is triggered next time, only changed files can be passed into the flow at the entry point(which is chord.filter()), other files will use caches at the exit point(which is chord.join()).

You may ask how unchanged files get restored at the exit point, gulp-chord-cache did a little trick to implement this, it replaced all unchanged file contens with an empty string at the entry point, then restored caches back at the exit pointer, so basically unchanged file contents did pass through the flow, but they were empty strings there.

How to use

Check the demo here.

Install gulp-chord-cache.

yarn add gulp-chord-cache

Configure packages.json and gulpfile.js

    ...
    "scripts": {
        "build": "gulp"
    },
    ...
import gulp from 'gulp';
import chord from 'gulp-chord-cache';

gulp.task('build', function () {
    return gulp.src([
        // source files
    ])
        // other plugins
        .pipe(chord.filter()) // <-- entry pointer
        // other plugins, only changed files will be handled
        .pipe(chord.join()) // <-- exit pointer
        // other plugins
        // ...
});

// 'build' task will be triggered before 'watch' task
gulp.task('watch', ['build'], function () {
    return gulp.watch([
        // source files
    ], ['build']);
});

gulp.task('default', ['watch']);

Run your task

yarn build

License

Package Sidebar

Install

npm i gulp-chord-cache

Weekly Downloads

0

Version

1.0.2

License

WTFPL

Last publish

Collaborators

  • oyang