Automatically detects and combines duplicated css selectors so you don't have to :smile:
'use strict';
const fs = require('fs');
const postcss = require('postcss');
const css = fs.readFileSync('src/app.css');
postcss([require('postcss-combine-duplicated-selectors')])
.process(css, {from: 'src/app.css', to: 'app.css'})
.then((result) => {
fs.writeFileSync('app.css', result.css);
if (result.map) fs.writeFileSync('app.css.map', result.map);
});
postcss --use postcss-combine-duplicated-selectors *.css
Input
.module {
color: green
}
.another-module {
color: blue
}
.module {
background: red
}
.another-module {
background: yellow
}
Output
.module {
color: green;
background: red
}
.another-module {
color: blue;
background: yellow
}
If you have code with media queries, pass code through mq-packer before postcss-combine-duplicated-selectors to ensure optimal results.