What is postcss-normalize-whitespace?
The postcss-normalize-whitespace npm package is a PostCSS plugin designed to normalize and minimize the whitespace in your CSS. It helps in reducing the file size and improving the readability of the CSS by consistently formatting the whitespace.
What are postcss-normalize-whitespace's main functionalities?
Minifying CSS
This feature allows you to compress your CSS by removing unnecessary whitespace, which can include spaces, tabs, and newlines that are not required for the CSS to function properly.
const postcss = require('postcss');
const normalizeWhitespace = require('postcss-normalize-whitespace');
postcss([normalizeWhitespace]).process('h1 { color: red; }').then(result => {
console.log(result.css); // Output: 'h1{color:red}'
});
Other packages similar to postcss-normalize-whitespace
cssnano
cssnano is a modular minifier that includes various optimizations, including whitespace normalization. It is more comprehensive than postcss-normalize-whitespace as it provides a wide range of optimizations beyond just whitespace normalization.
clean-css
clean-css is another powerful CSS minifier that offers advanced optimizations. It can perform many transformations to reduce CSS size, including whitespace normalization. It is similar to cssnano in its broad scope of features.
uglifycss
uglifycss is a simple tool for CSS minification that also includes whitespace normalization. It is less modular than cssnano and focuses on providing a straightforward solution for CSS compression.
postcss-normalize-whitespace
Normalize whitespace with PostCSS.
Install
With npm do:
npm install postcss-normalize-whitespace --save
Example
Input
h1{
width: calc(10px - ( 100px / var(--test) ))
}
Output
h1{
width: calc(10px - 100px / var(--test))
}
Usage
See the PostCSS documentation for
examples for your environment.
Contributors
See CONTRIBUTORS.md.
License
MIT Ā© Ben Briggs