59

minified-size - command-line tool to estimate the size of minified and gzipped f...

 5 years ago
source link: https://www.tuicool.com/articles/hit/Yj6NvqB
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

minified-size

NvINfe7.png!web

Estimates the size of minified and gzipped JavaScript files. Check, how much space will a particular script take in the minified output.

Command-line usage

Make sure that you have NodeJS >= 8 installed. Install the minified-size package globally:

$ npm install -g minified-size

Print the original, expected minified and gzipped sizes of a sample file:

$ minified-size lib/index.js
lib/index.js: 2.54 kB, 1.48 kB, 643 B

Running minified-size without any parameters will print usage instructions:

Usage: minified-size [options] <file>, ... | --

  Estimates the size of minified and gzipped JavaScript files.

  Options:

    -V, --version           output the version number
    -j, --json              print results in the JSON format
    -r, --raw-sizes         print sizes in bytes as integers
    -o, --no-original-size  prevents printing the size of the original code
    -m, --no-minified-size  prevents printing the size of the minified code
    -g, --no-gzipped-size   prevents printing the size of the gzipped code
    -h, --help              output usage information

  All three sizes are estimated by default. File paths may contain wildcards.
  If "--" is entered instead of files, the standard input will be read.

Programmatic usage

Make sure that you use NodeJS >= 8. Install the minified-size package locally:

npm install --save minified-size

Get the original, expected minified and gzipped sizes (in bytes) of a sample file:

const minifiedSize = require('minified-size')
const files = [ 'lib/index.js' ]
const results = await minifiedSize({ files })
// [ { file: 'lib/index.js',
//     originalSize: 2544,
//     minifiedSize: 1482,
//     gzippedSize: 643 } ]

Options

  • files - an array of strings with file paths to load and process
  • streams - an array of readable streams with source code to process
  • sources - an array of strings with source code to process
  • gzip - a boolean to disable estimating the gzipped output size, or an object with options for gzip .

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

Release History

  • 2018-08-31 v0.2.2 Support Windows paths
  • 2018-08-31 v0.2.0 Support source code read from standard input
  • 2018-08-31 v0.1.0 Support wildcards in the input file paths
  • 2018-08-31 v0.0.1 Initial release

License

Copyright (c) 2018 Ferdinand Prantl

Licensed under the MIT license.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK