gulp-cache-files
A disk based files caching task for gulp. This plugin based on file mtime by default (could use another file property after some configurations see below) it writes json file with formatted relative path as key and mtime as value. One of the main features of this plugin is that it can deal with projects where source folder is dist folder (it could be useful for saving disk space when you have a lot of images in project).
Installation
Install package with NPM and add it to your development dependencies:
npm install --save-dev gulp-cache-files
Examples
Basic example of using the cache to manage image minification with the imagemin module.
var gulp = ;var imagemin = ;var cacheFiles = ; gulp;
{read: false}
option used to do not load file contents, which increases performance (file contents will be passed through the pipeline inside filter function)
This will create a cache file named manifest.json
of all files passed through the pipeline to be excluded from subsequent runs. If a file that has been cached is updated, the cache will recognize this and pass the file through to update it in the manifest.json file.
*cache file (manifest.json
) could be added to version control for saving time of other developers
When you need 2 or more uses of gulp-cache-files module you should use require('gulp-cache-files').Prototype
as on example below:
var gulp = ;var imagemin = ;var jshint = ;var CacheFiles = Prototype; gulp; gulp;
Use of manifest function separately from filter function:
var gulp = ;var cacheFiles = ; gulp;
it just writes file.stat.mtime.getTime() as value and formatted* relative path as key into file 'files-mtimes.json'
*formatted means that it replaces Windows backslashes with such rule path.replace(/\\/g, '/')
Compare custom file properties:
var gulp = ;var imagemin = ;var cacheFiles = ;var Q = ;var fs = ; gulp;
API
filter(dest)
-
dest -
string
Path to cache file (manifest.json).default: -
'./gulp-cache-files/manifest.json'
filter(options)
-
options.dest -
string
As above. -
options.comparator -
function
Compares cached file property with uncached (by default it is file.stat.mtime)options.comparator(criteria, file [, manifest])
criteria - Cached value from cache file (manifest.json)
file - File object passed through stream
manifest - (optional) Object where formatted relative path is a key and file property as a value
{"fixtures/foo.png":1497680208602,"fixtures/bar.png":1497680208623}
default:
{return criteria === filestatmtime;}
manifest(name)
-
name -
string
name of cache file. (works only if used in separate gulp task without filter function above)default: -
'manifest.json'
manifest(options)
-
options.name -
string
As above. -
options.criteria -
function
Returns property or kew promise with this property which will be stored in cache file as value {"fixtures/foo.png":1497680208602}options.criteria(file)
file - File object passed through stream
default:
{return Q;}Q
here is just initialized instance of kew framework (var Q = require('kew');
)
License
MIT