npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gulp-size-difference

v1.1.0

Published

Display files size difference between before and after point of pipeline stream. Designed for measuring efficiency minifying tools like uglify or cssnano.

Downloads

9

Readme

Display files size difference between before and after point of pipeline stream. Designed for measuring efficiency minifying tools like uglify or cssnano.

version license

This package was created for my other project disco-gulp look here for full examples. Based on gulp-sizediff but provides more flexible output, and some refactoring to modern JS

Install

$ npm install --save-dev gulp-size-difference

Usage

import sizeDifference from 'gulp-size-difference';

gulp.src(currentPaths.development.js + "**/*.js")
  .pipe(plumber({
    errorHandler: errorHandler
  }))
  .pipe(sizeDifference.start())
  .pipe(uglify())
  .pipe(sizeDifference.stop({title: `JS ${group}`}))
  .pipe(rename({"suffix": ".min"}))
  .pipe(gulp.dest(currentPaths.production.js))
  .on("end", _ => {
    callback();
   });

Standard output

[00:00:00] Starting 'post-js'...
[00:00:00] JS example1.js (saved 116 B - 39%)
[00:00:00] JS example2.js (saved 0 B - 0%)
[00:00:00] Finished 'post-js' after 72 ms
[00:00:00] Starting 'post-js'...
[00:00:00] JS all files (saved 4.83 kB - 41.8%)
[00:00:00] Finished 'post-js' after 74 ms

sizeDiff.start() or sizeDiff()

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

sizeDiff.stop(options)

Counts and outputs the difference between saved size and the current filesize.

options

title

Type: string
Default: ''

Give it a title so it's possible to distinguish the output of multiple instances logging at once.

allFiles

Type: boolean
Default: false

Run formatData for every file instead of just the total size diff.

customFormat

Type: function
Default: 'formatData()'

Customise the output of this by using the format function. An example:

const formatDiff = (title = '', file = '', data = {}, isFile = false) => {
    title = title ? chalk.cyan(title) : title;
    file = file ? ' ' + chalk.green(file) : file;

    let message = `${title}${file}`;

    if (isFile) {
        message += chalk.white(` ~ saved ${prettyBytes(data.diffBytes)} (${Math.round(data.diffPercent * 100)}%)`);
    } else {
        const stats = [
            `Files count: ${data.filesCount}`,
            `Initial size: ${prettyBytes(data.initialSize)}`,
            `Final size: ${prettyBytes(data.finalSize)}`,
            `Difference bytes: ${prettyBytes(data.diffBytes)}`,
            `Difference percent: ${Math.round(data.diffPercent * 100)}%`,
            `Compression ratio: ${data.compressionRatio.toFixed(2)}`
        ];
        stats.forEach(filePath => {
            message += chalk.white(`\n\r${filePath}`);
        });
    }

    log(message);
}

import sizeDifference from 'gulp-size-difference';

gulp.src(currentPaths.development.js + "**/*.js")
    .pipe(plumber({
        errorHandler: errorHandler
    }))
    .pipe(sizeDifference.start())
    .pipe(uglify())
    .pipe(sizeDifference.stop({title: `JS ${group}`, customFormat: formatDiff}))
    .pipe(rename({"suffix": ".min"}))
    .pipe(gulp.dest(currentPaths.production.js))
    .on("end", _ => {
        callback();
    });
[00:00:00] Starting 'post-js'...
[00:00:00] JS example1.js ~ saved 116 B (39%)
[00:00:00] JS example2.js ~ saved 0 B (0%)
[00:00:00] Finished 'post-js' after 72 ms
[00:00:00] Starting 'post-js'...
[00:00:00] JS all files
Files count: 2
Initial size: 190 B
Final size: 74 B
Difference bytes: 116 B
Difference percent: 39%
Compression ratio: 0.61
[00:00:00] Finished 'post-js' after 74 ms
title

Type: string

String given with sizeDiff.stop()

file

Type: string

String relative path to file or all files text.

data

Type: Object

Difference data object

  • Files count: data.filesCount
  • Initial size: data.initialSize
  • Final size: data.finalSize
  • Difference bytes: data.diffBytes
  • Pretty initial size: data.prettyInitialSize
  • Pretty final size: data.prettyFinalSize
  • Pretty difference bytes: data.prettyDiffBytes
  • Difference percent: data.diffPercent
  • Compression ratio: data.compressionRatio
options

Type: Object

Passed options object for detecting output mode.


Like my work? Buy me a beer! 🍺

Donate