https://github.com/voorjaar/css-chosen
Dead simple CSS purge tool.
https://github.com/voorjaar/css-chosen
css purge
Last synced: about 2 months ago
JSON representation
Dead simple CSS purge tool.
- Host: GitHub
- URL: https://github.com/voorjaar/css-chosen
- Owner: voorjaar
- License: mit
- Created: 2021-02-08T06:53:46.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-02-09T05:12:52.000Z (over 4 years ago)
- Last Synced: 2025-02-14T03:15:41.989Z (3 months ago)
- Topics: css, purge
- Language: TypeScript
- Homepage: https://github.com/voorjaar/css-chosen
- Size: 24.4 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# css-chosen
Dead simple CSS purge tool.
## Installation
```sh
npm install css-chosen --save-dev
```## How
The project was inspired by [uncss](https://github.com/uncss/uncss), we both tend to use dom's `querySelector` method. But we use [css-select](https://github.com/fb55/css-select) to select css rules, which allows us to remove the dependency of [jsdom](https://github.com/jsdom/jsdom), so it will be smaller and faster.
The process by which **css-chosen** removes the unused rules is as follows:
1. The HTML files are loaded by [htmlparser2](https://github.com/fb55/htmlparser2) to get doms.
2. All the stylesheets are parsed by a simple build-in css parser.
3. `CSSselect.selectOne` filters out selectors that are not found in the HTML files.
4. The remaining rules are converted back to CSS.## Usage
[windicss](https://github.com/voorjaar/windicss) uses **css-chosen** to purge base styles added by third-party plugins.