Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bezoerb/postcss-discard
PostCSS plugin to discard rules, atrules or declarations by selector, RegExp or callback function
https://github.com/bezoerb/postcss-discard
Last synced: 14 days ago
JSON representation
PostCSS plugin to discard rules, atrules or declarations by selector, RegExp or callback function
- Host: GitHub
- URL: https://github.com/bezoerb/postcss-discard
- Owner: bezoerb
- License: mit
- Created: 2018-05-06T21:37:50.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2023-02-16T22:54:32.000Z (over 1 year ago)
- Last Synced: 2024-10-18T19:17:27.013Z (26 days ago)
- Language: JavaScript
- Size: 1.59 MB
- Stars: 12
- Watchers: 3
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# PostCSS Discard [![Build Status][ci-img]][ci]
[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## Usage
```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` |
| rule | `String`, `RegExp`, `Function` | Match rule like `.big-background-image {...}` |
| decl | `String`, `RegExp`, `Function` | Match declarations |
| css | `String` | 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`](http://api.postcss.org/).
- `value` Current value.Return true if the element should be discarded.
## Examples
### Diffing stylesheets
```js
postcss(discard({css: 'STYLES TO BE REMOVED'})).process('ORIGINAL CSS').css;
```### Discard by specifying rules
```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%;
}
```