PostCSS plugin to discard rules, atrules or declarations by selector, RegExp or callback function
npm install postcss-discard[PostCSS] plugin to discard rules by selector, RegExp, or @type. Also usable to generate a diff from two stylesheets
[postcss]: https://github.com/postcss/postcss
[ci-img]: https://github.com/bezoerb/postcss-discard/workflows/Tests/badge.svg
[ci]: https://github.com/bezoerb/postcss-discard/actions?workflow=Tests
``js`
const discard = require('postcss-discard');
postcss([discard(options)]);
See [PostCSS] docs for examples for your environment.
#### Options
| Name | Type | Description |
| ------ | ------------------------------ | --------------------------------------------- |
| atrule | String, RegExp, Function | Match atrule like @font-face |String
| rule | , RegExp, Function | Match rule like .big-background-image {...} |String
| decl | , RegExp, Function | Match declarations |String
| css | | CSS String or path to file containing css |
You can also pass a filter function for any of the supported types.
The function is invoked with two arguments (node, value).
- node The currently processed AST node generated by postcss.value
- Current value.
Return true if the element should be discarded.
`js`
postcss(discard({css: 'STYLES TO BE REMOVED'})).process('ORIGINAL CSS').css;
`css
.bg {
width: 100%;
height: 100%;
background-image: url('some/big/image.png');
}
@font-face {
font-family: 'My awesome font';
}
@media print {
...;
}
`
`js`
postcss([
discard({
atrule: ['@font-face', /print/],
}),
]);
`css``
.bg {
width: 100%;
height: 100%;
}