Security News
Cloudflare Adds Security.txt Setup Wizard
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
postcss-merge-rules
Advanced tools
The postcss-merge-rules npm package is designed to optimize CSS by merging CSS rules with identical selectors or declarations. This can lead to smaller CSS files and potentially faster load times for web pages.
Merging based on identical selectors
This feature combines rules with identical selectors into a single rule. In the code sample, two rules for the 'a' selector are merged into one.
const postcss = require('postcss');
const mergeRules = require('postcss-merge-rules');
const css = `a { color: blue; }
a { font-size: 14px; }`;
postcss([mergeRules()])
.process(css, { from: undefined })
.then(result => console.log(result.css));
Merging based on identical declarations
This feature merges rules that have identical declarations but different selectors, creating a grouped selector. The code sample demonstrates merging two rules that apply the same color declaration to different selectors.
const postcss = require('postcss');
const mergeRules = require('postcss-merge-rules');
const css = `a { color: blue; }
b { color: blue; }`;
postcss([mergeRules()])
.process(css, { from: undefined })
.then(result => console.log(result.css));
cssnano is a modular CSS minifier that includes functionalities similar to postcss-merge-rules as part of its optimizations. It can merge rules as well as perform other optimizations like reducing whitespace and minifying font weights.
clean-css is another CSS minifier that offers functionalities to merge CSS rules among other optimizations. It focuses on efficiency and performance, providing an alternative to postcss-merge-rules with a broader scope of CSS optimization techniques.
Merge CSS rules with PostCSS.
With npm do:
npm install postcss-merge-rules --save
This module will attempt to merge adjacent CSS rules:
a {
color: blue;
font-weight: bold
}
p {
color: blue;
font-weight: bold
}
a,p {
color: blue;
font-weight: bold
}
a {
color: blue
}
a {
font-weight: bold
}
a {
color: blue;
font-weight: bold
}
a {
font-weight: bold
}
p {
color: blue;
font-weight: bold
}
a,p {
font-weight: bold
}
p {
color: blue
}
See the PostCSS documentation for examples for your environment.
Pull requests are welcome. If you add functionality, then please add unit tests to cover it.
MIT © Ben Briggs
FAQs
Merge CSS rules with PostCSS.
The npm package postcss-merge-rules receives a total of 8,770,320 weekly downloads. As such, postcss-merge-rules popularity was classified as popular.
We found that postcss-merge-rules 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
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.
Security News
ENISA’s 2024 report highlights the EU’s top cybersecurity threats, including rising DDoS attacks, ransomware, supply chain vulnerabilities, and weaponized AI.