package
Compare the compressed and uncompressed sizes of a CSS file before and after processing.
npm install css-sizeGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Compare the size of a CSS file after processing it to the original.
The functionality can be easily replaced by minifying the file and dividing the minified file size by the unminified file size.
Results are shown for uncompressed as well as when compressed using gzip and brotli. For most users, one of the compressed sizes will best represent what will be served to a client in production. It also provides a better comparison between the minified and the original CSS.
CSS is expected to processed by postcss plugins but can be used with
any processing code that returns a promise that resolves to an object
with a css property.
With npm do:
npm install css-size --savevar postcss = require('postcss');
var autoprefixer = require('autoprefixer');
var nano = require('cssnano');
var css = 'h1 {\n color: black;\n}\n';
var nanoOpts = {};
var cssSize = require("css-size");
function process(css, options) {
return postcss([ autoprefixer, nano(options) ]).process(css);
}
cssSize(css, nanoOpts, process).then(
cssSize(input, options, processor)Pass input of CSS to receive an object with information about the
original & minified sizes (uncompressed, gzipped, and brotli'd), plus
difference and percentage results. The options object is passed
through to the processor should you wish to compare sizes using
different options than the defaults.
cssSize.numeric(input, options, processor)Exactly like cssSize(...) except the results are returned as numbers
instead of preformatted strings. In numeric mode, the percentage value is a
fraction (rounded to 4 significant digits), instead of being scaled to 100%.
cssSize.table(input, options, processor)Use the table method instead to receive the results as a formatted table.
Type: string, buffer
Type: object
Type: function
The processor accepts as arguments the input and options and returns a
Promise that resolves to an object with a css property containing the
processed css output.
See the available options with:
$ css-size --helpjs-size: Display the size of a JS file.See CONTRIBUTORS.md.
MIT © Ben Briggs
ludovicofischer
livrerie@gmail.com