@fullhuman/postcss-purgecss 4.1.3 → 5.0.0
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/lib/postcss-purgecss.d.ts +164 -38
- package/lib/postcss-purgecss.esm.js +1 -1
- package/lib/postcss-purgecss.js +1 -1
- package/package.json +6 -6
- package/LICENSE +0 -21
- package/lib/postcss-purgecss.esm.d.ts +0 -38
|
@@ -1,38 +1,164 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
type
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
1
|
+
/**
|
|
2
|
+
* PostCSS Plugin for PurgeCSS
|
|
3
|
+
*
|
|
4
|
+
* Most bundlers and frameworks to build websites are using PostCSS.
|
|
5
|
+
* The easiest way to configure PurgeCSS is with its PostCSS plugin.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import * as postcss from 'postcss';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
declare type ComplexSafelist = {
|
|
16
|
+
standard?: StringRegExpArray;
|
|
17
|
+
/**
|
|
18
|
+
* You can safelist selectors and their children based on a regular
|
|
19
|
+
* expression with `safelist.deep`
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* const purgecss = await new PurgeCSS().purge({
|
|
25
|
+
* content: [],
|
|
26
|
+
* css: [],
|
|
27
|
+
* safelist: {
|
|
28
|
+
* deep: [/red$/]
|
|
29
|
+
* }
|
|
30
|
+
* })
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* In this example, selectors such as `.bg-red .child-of-bg` will be left
|
|
34
|
+
* in the final CSS, even if `child-of-bg` is not found.
|
|
35
|
+
*
|
|
36
|
+
*/
|
|
37
|
+
deep?: RegExp[];
|
|
38
|
+
greedy?: RegExp[];
|
|
39
|
+
variables?: StringRegExpArray;
|
|
40
|
+
keyframes?: StringRegExpArray;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @public
|
|
45
|
+
*/
|
|
46
|
+
declare type ExtractorFunction<T = string> = (content: T) => ExtractorResult;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @public
|
|
50
|
+
*/
|
|
51
|
+
declare type ExtractorResult = ExtractorResultDetailed | string[];
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @public
|
|
55
|
+
*/
|
|
56
|
+
declare interface ExtractorResultDetailed {
|
|
57
|
+
attributes: {
|
|
58
|
+
names: string[];
|
|
59
|
+
values: string[];
|
|
60
|
+
};
|
|
61
|
+
classes: string[];
|
|
62
|
+
ids: string[];
|
|
63
|
+
tags: string[];
|
|
64
|
+
undetermined: string[];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @public
|
|
69
|
+
*/
|
|
70
|
+
declare interface Extractors {
|
|
71
|
+
extensions: string[];
|
|
72
|
+
extractor: ExtractorFunction;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* PostCSS Plugin for PurgeCSS
|
|
77
|
+
*
|
|
78
|
+
* @param opts - PurgeCSS Options
|
|
79
|
+
* @returns the postCSS plugin
|
|
80
|
+
*
|
|
81
|
+
* @public
|
|
82
|
+
*/
|
|
83
|
+
declare const purgeCSSPlugin: postcss.PluginCreator<UserDefinedOptions>;
|
|
84
|
+
export default purgeCSSPlugin;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* @public
|
|
88
|
+
*/
|
|
89
|
+
declare interface RawContent<T = string> {
|
|
90
|
+
extension: string;
|
|
91
|
+
raw: T;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* @public
|
|
96
|
+
*/
|
|
97
|
+
declare interface RawCSS {
|
|
98
|
+
raw: string;
|
|
99
|
+
name?: string;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* @public
|
|
104
|
+
*/
|
|
105
|
+
declare type StringRegExpArray = Array<RegExp | string>;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* {@inheritDoc purgecss#UserDefinedOptions}
|
|
109
|
+
*
|
|
110
|
+
* @public
|
|
111
|
+
*/
|
|
112
|
+
export declare interface UserDefinedOptions extends Omit<UserDefinedOptions_2, "content" | "css"> {
|
|
113
|
+
content?: UserDefinedOptions_2["content"];
|
|
114
|
+
contentFunction?: (sourceFile: string) => Array<string | RawContent>;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Options used by PurgeCSS to remove unused CSS
|
|
119
|
+
*
|
|
120
|
+
* @public
|
|
121
|
+
*/
|
|
122
|
+
declare interface UserDefinedOptions_2 {
|
|
123
|
+
/** {@inheritDoc Options.content} */
|
|
124
|
+
content: Array<string | RawContent>;
|
|
125
|
+
/** {@inheritDoc Options.css} */
|
|
126
|
+
css: Array<string | RawCSS>;
|
|
127
|
+
/** {@inheritDoc Options.defaultExtractor} */
|
|
128
|
+
defaultExtractor?: ExtractorFunction;
|
|
129
|
+
/** {@inheritDoc Options.extractors} */
|
|
130
|
+
extractors?: Array<Extractors>;
|
|
131
|
+
/** {@inheritDoc Options.fontFace} */
|
|
132
|
+
fontFace?: boolean;
|
|
133
|
+
/** {@inheritDoc Options.keyframes} */
|
|
134
|
+
keyframes?: boolean;
|
|
135
|
+
/** {@inheritDoc Options.output} */
|
|
136
|
+
output?: string;
|
|
137
|
+
/** {@inheritDoc Options.rejected} */
|
|
138
|
+
rejected?: boolean;
|
|
139
|
+
/** {@inheritDoc Options.rejectedCss} */
|
|
140
|
+
rejectedCss?: boolean;
|
|
141
|
+
/** {@inheritDoc Options.sourceMap } */
|
|
142
|
+
sourceMap?: boolean | (postcss.SourceMapOptions & { to?: string });
|
|
143
|
+
/** {@inheritDoc Options.stdin} */
|
|
144
|
+
stdin?: boolean;
|
|
145
|
+
/** {@inheritDoc Options.stdout} */
|
|
146
|
+
stdout?: boolean;
|
|
147
|
+
/** {@inheritDoc Options.variables} */
|
|
148
|
+
variables?: boolean;
|
|
149
|
+
/** {@inheritDoc Options.safelist} */
|
|
150
|
+
safelist?: UserDefinedSafelist;
|
|
151
|
+
/** {@inheritDoc Options.blocklist} */
|
|
152
|
+
blocklist?: StringRegExpArray;
|
|
153
|
+
/** {@inheritDoc Options.skippedContentGlobs} */
|
|
154
|
+
skippedContentGlobs?: Array<string>;
|
|
155
|
+
/** {@inheritDoc Options.dynamicAttributes} */
|
|
156
|
+
dynamicAttributes?: string[];
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* @public
|
|
161
|
+
*/
|
|
162
|
+
declare type UserDefinedSafelist = StringRegExpArray | ComplexSafelist;
|
|
163
|
+
|
|
164
|
+
export { }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e,
|
|
1
|
+
import*as e from"path";import{PurgeCSS as s,defaultOptions as t,standardizeSafelist as o,mergeExtractorSelectors as r}from"purgecss";const n=function(n){if(void 0===n)throw new Error("PurgeCSS plugin does not have the correct options");return{postcssPlugin:"postcss-purgecss",OnceExit:(c,i)=>async function(n,c,{result:i}){const a=new s;let l;try{const s=e.resolve(process.cwd(),"purgecss.config.js");l=await import(s)}catch{}const p={...t,...l,...n,safelist:o((null==n?void 0:n.safelist)||(null==l?void 0:l.safelist))};n&&"function"==typeof n.contentFunction&&(p.content=n.contentFunction(c.source&&c.source.input.file||"")),a.options=p,p.variables&&(a.variablesStructure.safelist=p.safelist.variables||[]);const{content:u,extractors:f}=p,m=u.filter((e=>"string"==typeof e)),g=u.filter((e=>"object"==typeof e)),v=await a.extractSelectorsFromFiles(m,f),d=await a.extractSelectorsFromString(g,f),S=r(v,d);a.walkThroughCSS(c,S),a.options.fontFace&&a.removeUnusedFontFaces(),a.options.keyframes&&a.removeUnusedKeyframes(),a.options.variables&&a.removeUnusedCSSVariables(),a.options.rejected&&a.selectorsRemoved.size>0&&(i.messages.push({type:"purgecss",plugin:"postcss-purgecss",text:`purging ${a.selectorsRemoved.size} selectors:\n ${Array.from(a.selectorsRemoved).map((e=>e.trim())).join("\n ")}`}),a.selectorsRemoved.clear())}(n,c,i)}};n.postcss=!0;export{n as default};
|
package/lib/postcss-purgecss.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("purgecss");function
|
|
1
|
+
"use strict";var e=require("path"),t=require("purgecss");function r(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var s=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,s.get?s:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var s=r(e);const o=function(e){if(void 0===e)throw new Error("PurgeCSS plugin does not have the correct options");return{postcssPlugin:"postcss-purgecss",OnceExit:(o,n)=>async function(e,o,{result:n}){const c=new t.PurgeCSS;let i;try{const e=s.resolve(process.cwd(),"purgecss.config.js");i=await function(e){return Promise.resolve().then((function(){return r(require(e))}))}(e)}catch{}const a={...t.defaultOptions,...i,...e,safelist:t.standardizeSafelist((null==e?void 0:e.safelist)||(null==i?void 0:i.safelist))};e&&"function"==typeof e.contentFunction&&(a.content=e.contentFunction(o.source&&o.source.input.file||"")),c.options=a,a.variables&&(c.variablesStructure.safelist=a.safelist.variables||[]);const{content:u,extractors:l}=a,f=u.filter((e=>"string"==typeof e)),p=u.filter((e=>"object"==typeof e)),d=await c.extractSelectorsFromFiles(f,l),g=await c.extractSelectorsFromString(p,l),v=t.mergeExtractorSelectors(d,g);c.walkThroughCSS(o,v),c.options.fontFace&&c.removeUnusedFontFaces(),c.options.keyframes&&c.removeUnusedKeyframes(),c.options.variables&&c.removeUnusedCSSVariables(),c.options.rejected&&c.selectorsRemoved.size>0&&(n.messages.push({type:"purgecss",plugin:"postcss-purgecss",text:`purging ${c.selectorsRemoved.size} selectors:\n ${Array.from(c.selectorsRemoved).map((e=>e.trim())).join("\n ")}`}),c.selectorsRemoved.clear())}(e,o,n)}};o.postcss=!0,module.exports=o;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fullhuman/postcss-purgecss",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "PostCSS plugin for PurgeCSS",
|
|
5
5
|
"author": "FoundrySH <no-reply@foundry.sh>",
|
|
6
6
|
"homepage": "https://purgecss.com",
|
|
@@ -20,16 +20,17 @@
|
|
|
20
20
|
"url": "git+https://github.com/FullHuman/purgecss.git"
|
|
21
21
|
},
|
|
22
22
|
"scripts": {
|
|
23
|
-
"
|
|
23
|
+
"build": "ts-node build.ts",
|
|
24
|
+
"test": "jest"
|
|
24
25
|
},
|
|
25
26
|
"bugs": {
|
|
26
27
|
"url": "https://github.com/FullHuman/purgecss/issues"
|
|
27
28
|
},
|
|
28
29
|
"dependencies": {
|
|
29
|
-
"purgecss": "^
|
|
30
|
+
"purgecss": "^5.0.0"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
|
-
"postcss": "^8.
|
|
33
|
+
"postcss": "^8.4.4"
|
|
33
34
|
},
|
|
34
35
|
"peerDependencies": {
|
|
35
36
|
"postcss": "^8.0.0"
|
|
@@ -37,6 +38,5 @@
|
|
|
37
38
|
"publishConfig": {
|
|
38
39
|
"access": "public",
|
|
39
40
|
"registry": "https://registry.npmjs.org/"
|
|
40
|
-
}
|
|
41
|
-
"gitHead": "37e5053a446880d12fd2f55abfc362c3dac9c49c"
|
|
41
|
+
}
|
|
42
42
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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.
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import * as postcss from "postcss";
|
|
2
|
-
type StringRegExpArray = Array<RegExp | string>;
|
|
3
|
-
type ComplexSafelist = {
|
|
4
|
-
standard?: StringRegExpArray;
|
|
5
|
-
deep?: RegExp[];
|
|
6
|
-
greedy?: RegExp[];
|
|
7
|
-
variables?: StringRegExpArray;
|
|
8
|
-
keyframes?: StringRegExpArray;
|
|
9
|
-
};
|
|
10
|
-
type UserDefinedSafelist = StringRegExpArray | ComplexSafelist;
|
|
11
|
-
interface RawContent$0<T = string> {
|
|
12
|
-
extension: string;
|
|
13
|
-
raw: T;
|
|
14
|
-
}
|
|
15
|
-
type ExtractorFunction$0<T = string> = (content: T) => string[];
|
|
16
|
-
interface Extractors$0 {
|
|
17
|
-
extensions: string[];
|
|
18
|
-
extractor: ExtractorFunction$0;
|
|
19
|
-
}
|
|
20
|
-
interface UserDefinedOptions$0 {
|
|
21
|
-
content?: Array<string | RawContent$0>;
|
|
22
|
-
contentFunction?: (sourceFile: string) => Array<string | RawContent$0>;
|
|
23
|
-
defaultExtractor?: ExtractorFunction$0;
|
|
24
|
-
extractors?: Array<Extractors$0>;
|
|
25
|
-
fontFace?: boolean;
|
|
26
|
-
keyframes?: boolean;
|
|
27
|
-
output?: string;
|
|
28
|
-
rejected?: boolean;
|
|
29
|
-
stdin?: boolean;
|
|
30
|
-
stdout?: boolean;
|
|
31
|
-
variables?: boolean;
|
|
32
|
-
safelist?: UserDefinedSafelist;
|
|
33
|
-
blocklist?: StringRegExpArray;
|
|
34
|
-
skippedContentGlobs?: Array<string>;
|
|
35
|
-
dynamicAttributes?: string[];
|
|
36
|
-
}
|
|
37
|
-
declare const purgeCSSPlugin: postcss.PluginCreator<UserDefinedOptions$0>;
|
|
38
|
-
export { purgeCSSPlugin as default };
|