gulp-cache-money

1.1.0 • Public • Published

Gulp Cache Money

Cache money is a gulp plugin that only runs the plugin if any of the files have changed. It saves the cache to a file called '.gulp-cache'.

Build status

Installation

Install via npm:

$ npm install --save-dev gulp-cache-money

Usage

Just add pass cache into the gulp chain right after you src your files.

var cache = require("gulp-cache-money")({
    cacheFile: __dirname + "/.cache"
});
 
gulp.task(function() {
    gulp.src("index.js")
        .pipe(
            cache() // Pipe in the cacher
            .on("cache-report", function(hits) { 
                console.log("%d cache hits.", hits.length); // Log how many hits
            })
        )
        .pipe(browserify())
        .dest("/build.js");
});

cache = cached( options )

This is the function exported from gulp-cache-money. Pass in an options object to configure the cache. The returned function is what you (call and) pass into your gulp build chain. gulp-cache-money works by md5'ing any incoming files and comparing the hashes, if none of the files within the vinyl-fs file stream have changed, the stream ends there otherwise all files are pushed down the chain.

  • cacheFile (String) -- The path to where you want to store you cache. Defaults to .gulp-cache in the directory of the entry file. (i.e. gulpfile.js)

cache( options )

This is the function you pass into your gulp chain which is returned from the exported function. This allows for configuration on a per stream basis. This function accepts the following options.

  • cascade (Boolean) -- This tells the caching engine whether each file in the file stream is individual. This means that the output of the stream is based on each individual file and not made of multiple files (i.e. no relation between files). For example, if one task concats multiple files into another single file, then one change to any of the files it concats together requires a whole new build. You would put cascade = true in this example because some files are dependant on other files and any changes made to the dependants are cascading. Conversely, if you had a task that simply transformed minified images, you would set cascade = false.

Events

The plugin emits two events to help you keep track of what's being cached.

cached

This event is emitted when a file in the stream hits the cache. It passes the path of the file that hit the cache.

cache-report

This event is emitted when the all the files have passed through the cache. It passes you an array of paths that hit the cache and never continues on the stream.

Caveats

Caching works by MD5'ing a file and comparing with the last known hash. It does not understand imports or require within files. I'd advise against using caching on any file that is an entry point to building other files. For example the entry file in browserify, if you make changes to some file the entry file requires and not the actual entry file, the task will not be run.

License & Author

Created and maintained by Adrian Cooney <adrian.cooney@teamwork.com>

The MIT License (MIT)

Copyright (c) <2015> <Teamwork.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Readme

Keywords

Package Sidebar

Install

npm i gulp-cache-money

Weekly Downloads

42

Version

1.1.0

License

MIT

Last publish

Collaborators

  • adriancooney