@invisiburu/gulp-memoize
v1.0.0
Published
A task memoize plugin for Gulp
Downloads
4
Readme
gulp-memoize
Based on the gulp-cache
A task memoize proxy task for gulp.
Install
npm i -D gulp-memoize
# or
yarn add -D gulp-memoize
Usage
import 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'))
);
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'))
});
API
memoize(pluginToMemoize [, options])
pluginToMemoize
Target task, the output of which will be memoized.
options
Options for gulp-memoize
plugin.
options.verbose
[Optional] Should the plugin report on every restored file
- Defaults to
false
options.key
[Optional] What to use to determine the uniqueness of an input file for this task.
Can return a string or a
Promise
that 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.contents
if a Buffer, orundefined
if a Stream.
options.memo
[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
options.clearMemoOnFlush
[Optional] Should the memo be cleared after the task execution
- Defaults to
true
License
Copyright (c) 2021 - present Maksym Nesterov Copyright (c) 2014 - present Jacob Gable