purgecss-from-pug 6.0.0 → 7.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +14 -3
- package/lib/purgecss-from-pug.d.ts +13 -2
- package/lib/purgecss-from-pug.esm.js +68 -1
- package/lib/purgecss-from-pug.js +70 -1
- package/package.json +3 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Full Human
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
# `purgecss-from-pug`
|
|
2
2
|
|
|
3
|
-
|
|
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.
|
|
4
4
|
|
|
5
5
|
## Usage
|
|
6
6
|
|
|
7
7
|
```
|
|
8
|
-
|
|
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
|
+
}
|
|
9
20
|
|
|
10
|
-
|
|
21
|
+
const purgecss = await new PurgeCSS().purge();
|
|
11
22
|
```
|
|
@@ -1,3 +1,15 @@
|
|
|
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
|
+
|
|
11
|
+
import type { ExtractorResultDetailed } from 'purgecss';
|
|
12
|
+
|
|
1
13
|
/**
|
|
2
14
|
* Get the potential selectors from Pug code
|
|
3
15
|
*
|
|
@@ -6,7 +18,6 @@
|
|
|
6
18
|
*
|
|
7
19
|
* @public
|
|
8
20
|
*/
|
|
9
|
-
declare const
|
|
10
|
-
export default purgeFromPug;
|
|
21
|
+
export declare const purgeCSSFromPug: (content: string) => ExtractorResultDetailed;
|
|
11
22
|
|
|
12
23
|
export { }
|
|
@@ -1 +1,68 @@
|
|
|
1
|
-
import
|
|
1
|
+
import lex from 'pug-lexer';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Pug extractor for PurgeCSS
|
|
5
|
+
*
|
|
6
|
+
* A PurgeCSS extractor for PUG files that automatically generates a list of
|
|
7
|
+
* used CSS selectors. This extractor can be used with PurgeCSS to eliminate
|
|
8
|
+
* unused CSS and reduce the size of your production builds.
|
|
9
|
+
*
|
|
10
|
+
* @packageDocumentation
|
|
11
|
+
*/
|
|
12
|
+
const getAttributeTokenValues = (token) => {
|
|
13
|
+
if (typeof token.val === "string") {
|
|
14
|
+
return (token.mustEscape ? token.val.replace(/"/g, "") : token.val).split(" ");
|
|
15
|
+
}
|
|
16
|
+
return [];
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Get the potential selectors from Pug code
|
|
20
|
+
*
|
|
21
|
+
* @param content - Pug code
|
|
22
|
+
* @returns the attributes, classes, ids, and tags from the Pug code
|
|
23
|
+
*
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
const purgeCSSFromPug = (content) => {
|
|
27
|
+
const tokens = lex(content);
|
|
28
|
+
const extractorResult = {
|
|
29
|
+
attributes: {
|
|
30
|
+
// always add to attributes, to handle things like [class*=foo]
|
|
31
|
+
names: ["class", "id"],
|
|
32
|
+
values: ["true", "false"],
|
|
33
|
+
},
|
|
34
|
+
classes: [],
|
|
35
|
+
ids: [],
|
|
36
|
+
tags: [],
|
|
37
|
+
undetermined: [],
|
|
38
|
+
};
|
|
39
|
+
for (const token of tokens) {
|
|
40
|
+
if (token.type === "tag") {
|
|
41
|
+
extractorResult.tags.push(token.val);
|
|
42
|
+
}
|
|
43
|
+
else if (token.type === "class") {
|
|
44
|
+
extractorResult.classes.push(...token.val.split(" "));
|
|
45
|
+
extractorResult.attributes.values.push(...token.val.split(" "));
|
|
46
|
+
}
|
|
47
|
+
else if (token.type === "id") {
|
|
48
|
+
extractorResult.ids.push(token.val);
|
|
49
|
+
extractorResult.attributes.values.push(token.val);
|
|
50
|
+
}
|
|
51
|
+
else if (token.type === "attribute") {
|
|
52
|
+
const tokenValues = getAttributeTokenValues(token);
|
|
53
|
+
if (token.name === "class") {
|
|
54
|
+
extractorResult.classes.push(...tokenValues);
|
|
55
|
+
}
|
|
56
|
+
else if (token.name === "id") {
|
|
57
|
+
extractorResult.ids.push(...tokenValues);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
extractorResult.attributes.names.push(token.name);
|
|
61
|
+
}
|
|
62
|
+
extractorResult.attributes.values.push(...tokenValues);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return extractorResult;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export { purgeCSSFromPug };
|
package/lib/purgecss-from-pug.js
CHANGED
|
@@ -1 +1,70 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var lex = require('pug-lexer');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Pug extractor for PurgeCSS
|
|
7
|
+
*
|
|
8
|
+
* A PurgeCSS extractor for PUG files that automatically generates a list of
|
|
9
|
+
* used CSS selectors. This extractor can be used with PurgeCSS to eliminate
|
|
10
|
+
* unused CSS and reduce the size of your production builds.
|
|
11
|
+
*
|
|
12
|
+
* @packageDocumentation
|
|
13
|
+
*/
|
|
14
|
+
const getAttributeTokenValues = (token) => {
|
|
15
|
+
if (typeof token.val === "string") {
|
|
16
|
+
return (token.mustEscape ? token.val.replace(/"/g, "") : token.val).split(" ");
|
|
17
|
+
}
|
|
18
|
+
return [];
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Get the potential selectors from Pug code
|
|
22
|
+
*
|
|
23
|
+
* @param content - Pug code
|
|
24
|
+
* @returns the attributes, classes, ids, and tags from the Pug code
|
|
25
|
+
*
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
const purgeCSSFromPug = (content) => {
|
|
29
|
+
const tokens = lex(content);
|
|
30
|
+
const extractorResult = {
|
|
31
|
+
attributes: {
|
|
32
|
+
// always add to attributes, to handle things like [class*=foo]
|
|
33
|
+
names: ["class", "id"],
|
|
34
|
+
values: ["true", "false"],
|
|
35
|
+
},
|
|
36
|
+
classes: [],
|
|
37
|
+
ids: [],
|
|
38
|
+
tags: [],
|
|
39
|
+
undetermined: [],
|
|
40
|
+
};
|
|
41
|
+
for (const token of tokens) {
|
|
42
|
+
if (token.type === "tag") {
|
|
43
|
+
extractorResult.tags.push(token.val);
|
|
44
|
+
}
|
|
45
|
+
else if (token.type === "class") {
|
|
46
|
+
extractorResult.classes.push(...token.val.split(" "));
|
|
47
|
+
extractorResult.attributes.values.push(...token.val.split(" "));
|
|
48
|
+
}
|
|
49
|
+
else if (token.type === "id") {
|
|
50
|
+
extractorResult.ids.push(token.val);
|
|
51
|
+
extractorResult.attributes.values.push(token.val);
|
|
52
|
+
}
|
|
53
|
+
else if (token.type === "attribute") {
|
|
54
|
+
const tokenValues = getAttributeTokenValues(token);
|
|
55
|
+
if (token.name === "class") {
|
|
56
|
+
extractorResult.classes.push(...tokenValues);
|
|
57
|
+
}
|
|
58
|
+
else if (token.name === "id") {
|
|
59
|
+
extractorResult.ids.push(...tokenValues);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
extractorResult.attributes.names.push(token.name);
|
|
63
|
+
}
|
|
64
|
+
extractorResult.attributes.values.push(...tokenValues);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return extractorResult;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
exports.purgeCSSFromPug = purgeCSSFromPug;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "purgecss-from-pug",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.2",
|
|
4
4
|
"description": "Pug extractor for PurgeCSS",
|
|
5
5
|
"author": "Ffloriel",
|
|
6
6
|
"homepage": "https://github.com/FullHuman/purgecss#readme",
|
|
@@ -31,5 +31,6 @@
|
|
|
31
31
|
"publishConfig": {
|
|
32
32
|
"access": "public",
|
|
33
33
|
"registry": "https://registry.npmjs.org/"
|
|
34
|
-
}
|
|
34
|
+
},
|
|
35
|
+
"gitHead": "e95398d961e03a809b5e3da75e3dae1813b46b68"
|
|
35
36
|
}
|