I am trying to find any Gulp module that can combine css rules having same property/value. Following example demonstrates my problem.
h2 {
font-size: 14px;
}
p {
font-size: 14px;
}
Output should be
h2, p {
font-size: 14px;
}
It would be great if there's way to solve this issue while compiling scss to css. Thanks in advance
You can use gulp-clean-css. For example, this will compile
index.scss
tobuild/index.css
given the output you asked for:gulp-clean-css uses clean-css, where merging the selectors like this is considered a "level 2 optimisation", which is why I set the level as an option above. You can look at those options for more details.
Update
In response to the comment below, you can use more aggressive merging:
Before (
index.scss
):After (
index.css
):