Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/DenyVeyten/postcss-deadcss
Plugin that helps to find dead CSS in stylesheets
https://github.com/DenyVeyten/postcss-deadcss
css optimization performance postcss postcss-deadcss
Last synced: 2 months ago
JSON representation
Plugin that helps to find dead CSS in stylesheets
- Host: GitHub
- URL: https://github.com/DenyVeyten/postcss-deadcss
- Owner: DenyVeyten
- License: isc
- Created: 2020-09-19T09:01:05.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-09-27T11:08:40.000Z (over 4 years ago)
- Last Synced: 2024-10-11T00:04:58.485Z (4 months ago)
- Topics: css, optimization, performance, postcss, postcss-deadcss
- Language: JavaScript
- Homepage:
- Size: 89.8 KB
- Stars: 30
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# postcss-deadcss
[PostCSS] plugin that helps to find dead css in a project.Implements technique from https://csswizardry.com/2018/01/finding-dead-css/
[PostCSS]: https://github.com/postcss/postcss
```css
/* Input example */
.foo {
color: red;
}
``````css
/* Output example */
.foo {
background-image: url('https://monitoring.host/pixel.png?.foo');
color: red;
}
```## Usage
**Step 1:** Install plugin:
```sh
npm install --save-dev postcss postcss-deadcss
```**Step 2:** Check you project for existed PostCSS config: `postcss.config.js`
in the project root, `"postcss"` section in `package.json`
or `postcss` in bundle config.If you do not use PostCSS, add it according to [official docs]
and set this plugin in settings. Alternatively, you can use the [postcss-cli] to run postcss-deadcss from CLI:```sh
npm install postcss-cli# after configuration:
npx postcss *.css -d output/
```See `npx postcss -h` for help.
**Step 3:** Add the plugin to plugins list:
```diff
module.exports = {
plugins: [
require('autoprefixer'),
+ require('postcss-deadcss')({
+ url: 'https://monitoring.host/pixel.png',
+ hash: true,
+ }),
]
}
```Available options:
| Name | Type | Default | Description |
|--------|---------|---------|-------------|
| url | string | `'https://monitoring.host/pixel.png'` | Base url with transparent image to load |
| hash | boolean | `false` | To use md5 hashes of seloctors for background image urls, otherwise to use URL ecoded selectors |
| append | boolean | `false` | To append background-image declaration instead of prepend it (this will break styling during testing, but is not required manual checks if background-image has been overwritten by other declaration below in the same rule or not)**Step 4:** Deploy css and [transparent image] and start monitoring requests to the image. After considered amount of time you can remove css rules that hasn't been requested or rewrite code when css rules are used too unfrequently. **Enjoy the results!** :tada:
[official docs]: https://github.com/postcss/postcss#usage
[postcss-cli]: https://github.com/postcss/postcss-cli
[transparent image]: pixel.png