Security News
The Unpaid Backbone of Open Source: Solo Maintainers Face Increasing Security Demands
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
postcss-discard-empty
Advanced tools
The postcss-discard-empty npm package is a PostCSS plugin that is used to remove empty rules, selectors, and at-rules from your CSS. This helps in reducing the size of the CSS file and cleaning up any unused or empty CSS declarations that may be left over after development or refactoring.
Discard empty rules
This feature removes CSS rules that have no declarations inside them. For example, 'a{}' would be removed from the CSS because it's an empty rule.
postcss([ require('postcss-discard-empty') ]).process('a{}').css
Discard empty at-rules
This feature removes at-rules that have no content. For example, '@media screen {}' would be removed because it contains no rules or declarations.
postcss([ require('postcss-discard-empty') ]).process('@media screen {}').css
Discard empty selectors
This feature removes selectors that have no declarations. In the given code, 'b{}' would be removed, leaving only the selector 'a' with its declaration.
postcss([ require('postcss-discard-empty') ]).process('a{ color: red; } b{}').css
cssnano is a modular minifier that includes functionalities to discard empty rules among other optimizations. It is more comprehensive than postcss-discard-empty as it performs a wide range of optimizations to reduce CSS size.
purgecss is a tool to remove unused CSS, which can also result in the removal of empty rules if they become empty after purging unused styles. It differs from postcss-discard-empty by focusing on removing unused selectors rather than just empty ones.
Discard empty rules and values with PostCSS.
Install via npm:
npm install postcss-discard-empty --save
var postcss = require('postcss')
var empty = require('postcss-discard-empty');
var css = '@font-face; h1 {} {color:blue} h2 {color:} h3 {color:red}';
console.log(postcss(empty()).process(css).css);
// => 'h3 {color:red}'
For more examples see the tests.
Pull requests are welcome. If you add functionality, then please add unit tests to cover it.
MIT © Ben Briggs
FAQs
Discard empty rules and values with PostCSS.
The npm package postcss-discard-empty receives a total of 9,088,484 weekly downloads. As such, postcss-discard-empty popularity was classified as popular.
We found that postcss-discard-empty demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 8 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.
Security News
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.