gulp-bytediff

Compare file sizes before and after your gulp build process.

npm install gulp-bytediff
54 downloads in the last week
146 downloads in the last month

gulp-bytediff Build Status NPM version Dependency Status

Compare file sizes before and after your gulp build process.

Install via npm:

npm install gulp-bytediff --save-dev

Example

Take any gulpplugin, or series of gulpplugins and see how much the build process added to, or removed from, your filesize. This example uses another of my modules, gulp-csso.

var gulp = require('gulp');
var bytediff = require('gulp-bytediff');
var csso = require('gulp-csso');

gulp.task('default', function() {
    gulp.src('main.css')
        .pipe(bytediff.start())
        .pipe(csso())
        .pipe(bytediff.stop())
        .pipe(gulp.dest('./out'));
});

API

bytediff.start() or bytediff()

Creates a new property on the file object that saves its current size.

bytediff.stop(formatFunction)

Outputs the difference between the property saved with the start() method and the current filesize.

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
npm loves you