gulp-bytediff
![Dependency Status](https://camo.githubusercontent.com/cb64dce36551fa3cf45598c0a93573cb9afeeb153071dd5e2abb784ac772f36b/68747470733a2f2f67656d6e617369756d2e636f6d2f62656e2d65622f67756c702d62797465646966662e737667)
Compare file sizes before and after your gulp build process.
With npm do:
npm install gulp-bytediff --save-dev
Take any gulp plugin, or series of gulp plugins, & see how much the build process impacted the file size. This example shows how much gulp-cssnano optimized a CSS file:
var gulp = require('gulp');
var bytediff = require('gulp-bytediff');
var cssnano = require('gulp-cssnano');
gulp.task('default', function() {
gulp.src('main.css')
.pipe(bytediff.start())
.pipe(cssnano())
.pipe(bytediff.stop())
.pipe(gulp.dest('./out'));
});
Creates a new property on the file object that saves its current size.
Outputs the difference between the property saved with the start()
method
and the current file size.
Customise the output of this by using the format function. An example:
// ...
.pipe(bytediff.stop(function(data) {
var difference = (data.savings > 0) ? ' smaller.' : ' larger.';
return data.fileName + ' is ' + data.percent + '%' + difference;
}))
.pipe(gulp.dest('./out'));
The function gets passed an object with the following properties:
- fileName
- startSize
- endSize
- savings
- percent
Pull requests are welcome. If you add functionality, then please add unit tests to cover it.
MIT © Ben Briggs