What is postcss-unique-selectors?
The postcss-unique-selectors npm package is a PostCSS plugin that removes duplicate CSS selectors within a rule. This helps in optimizing the CSS by ensuring that each selector is unique, which can reduce the size of the CSS file and improve maintainability.
Remove duplicate selectors
This feature removes duplicate selectors within a CSS rule. In the provided code sample, the duplicate 'a' selector is removed, resulting in 'a, b { color: red; }'.
const postcss = require('postcss');
const uniqueSelectors = require('postcss-unique-selectors');
const css = 'a, a, b { color: red; }';
postcss([uniqueSelectors])
.process(css)
.then(result => {
console.log(result.css); // Output: 'a, b { color: red; }'
});