Skip to content

Commit 797400d

Browse files
committed
docs: add documentation for purgecss-from-pug
#461
1 parent 39a855c commit 797400d

File tree

3 files changed

+44
-8
lines changed

3 files changed

+44
-8
lines changed

docs/extractors.md

+20-5
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,19 @@ Using a specific extractor for an extension should provide you with the best acc
4343
You can use an extractor by settings the extractors option in the PurgeCSS config file.
4444

4545
```js
46-
import purgeJs from "purgecss-from-js";
47-
import purgeHtml from "purgecss-from-html";
46+
import { purgeCSSFromPug } from "purgecss-from-pug";
47+
import { purgeCSSFromHtml } from "purgecss-from-html";
4848

4949
const options = {
5050
content: [], // files to extract the selectors from
5151
css: [], // css
5252
extractors: [
5353
{
54-
extractor: purgeJs,
55-
extensions: ["js"],
54+
extractor: purgeCSSFromPug,
55+
extensions: ["pug"],
5656
},
5757
{
58-
extractor: purgeHtml,
58+
extractor: purgeCSSFromHtml,
5959
extensions: ["html"],
6060
},
6161
],
@@ -67,6 +67,21 @@ export default options;
6767

6868
An extractor is a simple function that takes the content of a file as a string and returns an array of selectors. By convention, the name of the npm package is `purgecss-from-[typefile]` \(e.g. purgecss-from-pug\). Using this convention will allow users to look at the list of extractor on npm by searching `purgecss-from`.
6969

70+
The function can returns either an array of selectors (tags, classes, ids) or the object below for better accuracy:
71+
72+
```ts
73+
interface ExtractorResultDetailed {
74+
attributes: {
75+
names: string[];
76+
values: string[];
77+
};
78+
classes: string[];
79+
ids: string[];
80+
tags: string[];
81+
undetermined: string[];
82+
}
83+
```
84+
7085
```js
7186
const purgeFromJs = (content) => {
7287
// return array of css selectors

packages/purgecss-from-pug/README.md

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
# `purgecss-from-pug`
22

3-
> TODO: description
3+
A PurgeCSS extractor for PUG files that automatically generates a list of used CSS selectors from your PUG files. This extractor can be used with PurgeCSS to eliminate unused CSS and reduce the size of your production builds.
44

55
## Usage
66

77
```
8-
const purgecssFromPug = require('purgecss-from-pug');
8+
import { PurgeCSS } from 'purgecss'
9+
import { purgeCSSFromPug } from 'purgecss-from-pug'
10+
const options = {
11+
content: [], // files to extract the selectors from
12+
css: [], // css
13+
extractors: [
14+
{
15+
extractor: purgeCSSFromPug,
16+
extensions: ['pug']
17+
},
18+
]
19+
}
920
10-
// TODO: DEMONSTRATE API
21+
const purgecss = await new PurgeCSS().purge();
1122
```

packages/purgecss-from-pug/src/index.ts

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/**
2+
* Pug extractor for PurgeCSS
3+
*
4+
* A PurgeCSS extractor for PUG files that automatically generates a list of
5+
* used CSS selectors. This extractor can be used with PurgeCSS to eliminate
6+
* unused CSS and reduce the size of your production builds.
7+
*
8+
* @packageDocumentation
9+
*/
10+
111
import lex from "pug-lexer";
212
import type { ExtractorResultDetailed } from "purgecss";
313

0 commit comments

Comments
 (0)