Based on the gulp-cache
A task memoize proxy task for gulp.
npm i -D gulp-memoize
# or
yarn add -D gulp-memoizeimport gulp from 'gulp';
import favicons from 'gulp-favicons';
import srcset from 'gulp-srcset';
import memoize from 'gulp-memoize';
gulp.task('favicon', () =>
gulp.src('src/favicon.svg')
.pipe(memoize(
// Target plugin, the output of which will be memoized.
favicons(faviconsConfig),
// Options for `gulp-memoize` plugin.
{
// Report on every restored file
verbose: true
}
))
.pipe(gulp.dest('./favicons'))
);
gulp.task('images', () =>
gulp.src('src/**/*.{jpg,png,svg}')
.pipe(memoize(srcset(srcsetRules)))
.pipe(gulp.dest('./images'))
);Complex usage example
import fs from 'fs';
import gulp from 'gulp';
import jshint from 'gulp-jshint';
import memoize from 'gulp-memoize';
const jsHintVersion = '2.4.1';
const jshintOptions = fs.readFileSync('.jshintrc');
function makeHashKey(file) {
// Key off the file contents, jshint version and options
return `${file.contents.toString('utf8')}${jshintVersion}${jshintOptions}`;
}
gulp.task('lint', () =>
gulp.src('src/**/*.js')
.pipe(memoize(
// Target plugin, the output of which will be memoized.
jshint('.jshintrc'),
// Options for `gulp-memoize` plugin.
{
key: makeHashKey,
verbose: true
}
))
.pipe(jshint.reporter('default'))
});Target task, the output of which will be memoized.
Options for gulp-memoize plugin.
[Optional] Should the plugin report on every restored file
- Defaults to
false
[Optional] What to use to determine the uniqueness of an input file for this task.
-
Can return a string or a
Promisethat resolves to a string. -
The result of this method is converted to a unique MD5 hash automatically; no need to do this yourself.
-
Defaults to
file.contentsif a Buffer, orundefinedif a Stream.
[Optional] Custom Memo instance. Default is
new Map<string, Vinyl[]>().
-
Should implement the Map interface
-
Keys of the Memo are strings, values are arrays of Vinyl files
[Optional] Should the memo be cleared after the task execution
- Defaults to
true
Copyright (c) 2021 - present Maksym Nesterov Copyright (c) 2014 - present Jacob Gable