Luke Karrys lukekarrys/js-size


Get the size of some JS.

Host: GitHub

License: MIT

Language: JavaScript


js-size

Get the size of some JS.

NPM Build Status JavaScript Style Guide Greenkeeper badge

All sizes are shown gzipped using the gzip-size module. The gzipped size better represents what gets sent over-the-wire in a production application. It also provides a better baselines when comparing the original to the minified size.

Install

npm install --save js-size

Usage

const jssize = require('js-size')
require('./something-that-bundles-your-js').then((jsStr) => {
  console.log(jssize(js))
  // {
  //   original: '170.96 kB',
  //   minified: '77.19 kB',
  //   difference: '93.77 kB',
  //   percent: '45.15%'
  // }

  console.log(jssize.table(js))
  // ┌─────────────────┬───────────┐
  // │ Original (gzip) │ 170.96 kB │
  // ├─────────────────┼───────────┤
  // │ Minified (gzip) │ 77.19 kB  │
  // ├─────────────────┼───────────┤
  // │ Difference      │ 93.77 kB  │
  // ├─────────────────┼───────────┤
  // │ Percent         │ 45.15%    │
  // └─────────────────┴───────────┘
})

API

jssize(input, options)

input

Required
Type: string, buffer

Returns the original and minified sizes and the difference and percent minified.

jssize.table(input, options)

input

Required
Type: string, buffer

Returns all the same table but formatted as a cli table.

options (default, {})

es (default, false)

Whether to use uglify-es or not.

Uglify options

All other keys are passed directly to uglify. See the API Reference for available options.

CLI

$ npm install --global js-size
$ js-size

  Get the size of some JS.

  Usage
    js-size <file>
    cat <file.js> | js-size

  Options
    --config, -c Path to json config file to use for uglify options
    --es, -e Use uglify-es

  Example
    js-size index.js --es
    ┌─────────────────┬────────┐
    │ Original (gzip) │ 588 kB │
    ├─────────────────┼────────┤
    │ Minified (gzip) │ 446 kB │
    ├─────────────────┼────────┤
    │ Difference      │ 142 kB │
    ├─────────────────┼────────┤
    │ Percent         │ 75.85% │
    └─────────────────┴────────┘

License

MIT © Luke Karrys

Project Statistics

Sourcerank 7
Size 92.8 KB
Stars 8
Forks 3
Watchers 1
Open issues 0
Dependencies 254
Contributors 3
Tags 14
Created
Last updated
Last pushed

Top Contributors See all

Luke Karrys Greenkeeper Drew Fyock

Projects Referencing this Repo

js-size
Get the size of some JS.
Latest release 2.1.7 - Updated - 8 stars

Recent Tags See all

v2.1.7 September 08, 2017
v2.1.6 August 07, 2017
v2.1.5 August 06, 2017
v2.1.2 June 30, 2017
v2.1.1 May 10, 2017
v2.1.0 May 10, 2017
v2.0.0 August 31, 2016
v1.0.6 August 08, 2016
v1.0.5 April 02, 2015
v1.0.4 April 02, 2015
v1.0.3 February 10, 2015
v1.0.2 October 08, 2014
v1.0.1 October 08, 2014
v1.0.0 September 17, 2014

Something wrong with this page? Make a suggestion

Last synced: 2017-09-08 06:55:26 UTC

Login to resync this repository