@fullhuman/postcss-purgecss 4.1.3 → 6.0.0-alpha.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.
|
@@ -1,38 +1,164 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
+
export 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
|
+
export declare type ExtractorFunction<T = string> = (content: T) => ExtractorResult;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @public
|
|
50
|
+
*/
|
|
51
|
+
export declare type ExtractorResult = ExtractorResultDetailed | string[];
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @public
|
|
55
|
+
*/
|
|
56
|
+
export 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
|
+
export 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
|
+
* Options used by PurgeCSS to remove unused CSS
|
|
88
|
+
*
|
|
89
|
+
* @public
|
|
90
|
+
*/
|
|
91
|
+
export declare interface PurgeCSSUserDefinedOptions {
|
|
92
|
+
/** {@inheritDoc purgecss#Options.content} */
|
|
93
|
+
content: Array<string | RawContent>;
|
|
94
|
+
/** {@inheritDoc purgecss#Options.css} */
|
|
95
|
+
css: Array<string | RawCSS>;
|
|
96
|
+
/** {@inheritDoc purgecss#Options.defaultExtractor} */
|
|
97
|
+
defaultExtractor?: ExtractorFunction;
|
|
98
|
+
/** {@inheritDoc purgecss#Options.extractors} */
|
|
99
|
+
extractors?: Array<Extractors>;
|
|
100
|
+
/** {@inheritDoc purgecss#Options.fontFace} */
|
|
101
|
+
fontFace?: boolean;
|
|
102
|
+
/** {@inheritDoc purgecss#Options.keyframes} */
|
|
103
|
+
keyframes?: boolean;
|
|
104
|
+
/** {@inheritDoc purgecss#Options.output} */
|
|
105
|
+
output?: string;
|
|
106
|
+
/** {@inheritDoc purgecss#Options.rejected} */
|
|
107
|
+
rejected?: boolean;
|
|
108
|
+
/** {@inheritDoc purgecss#Options.rejectedCss} */
|
|
109
|
+
rejectedCss?: boolean;
|
|
110
|
+
/** {@inheritDoc purgecss#Options.sourceMap } */
|
|
111
|
+
sourceMap?: boolean | (postcss.SourceMapOptions & { to?: string });
|
|
112
|
+
/** {@inheritDoc purgecss#Options.stdin} */
|
|
113
|
+
stdin?: boolean;
|
|
114
|
+
/** {@inheritDoc purgecss#Options.stdout} */
|
|
115
|
+
stdout?: boolean;
|
|
116
|
+
/** {@inheritDoc purgecss#Options.variables} */
|
|
117
|
+
variables?: boolean;
|
|
118
|
+
/** {@inheritDoc purgecss#Options.safelist} */
|
|
119
|
+
safelist?: UserDefinedSafelist;
|
|
120
|
+
/** {@inheritDoc purgecss#Options.blocklist} */
|
|
121
|
+
blocklist?: StringRegExpArray;
|
|
122
|
+
/** {@inheritDoc purgecss#Options.skippedContentGlobs} */
|
|
123
|
+
skippedContentGlobs?: Array<string>;
|
|
124
|
+
/** {@inheritDoc purgecss#Options.dynamicAttributes} */
|
|
125
|
+
dynamicAttributes?: string[];
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* @public
|
|
130
|
+
*/
|
|
131
|
+
export declare interface RawContent<T = string> {
|
|
132
|
+
extension: string;
|
|
133
|
+
raw: T;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* @public
|
|
138
|
+
*/
|
|
139
|
+
export declare interface RawCSS {
|
|
140
|
+
raw: string;
|
|
141
|
+
name?: string;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* @public
|
|
146
|
+
*/
|
|
147
|
+
export declare type StringRegExpArray = Array<RegExp | string>;
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* {@inheritDoc purgecss#UserDefinedOptions}
|
|
151
|
+
*
|
|
152
|
+
* @public
|
|
153
|
+
*/
|
|
154
|
+
export declare interface UserDefinedOptions extends Omit<PurgeCSSUserDefinedOptions, "content" | "css"> {
|
|
155
|
+
content?: PurgeCSSUserDefinedOptions["content"];
|
|
156
|
+
contentFunction?: (sourceFile: string) => Array<string | RawContent>;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* @public
|
|
161
|
+
*/
|
|
162
|
+
export 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": "6.0.0-alpha.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": "^6.0.0-alpha.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"
|
|
@@ -38,5 +39,5 @@
|
|
|
38
39
|
"access": "public",
|
|
39
40
|
"registry": "https://registry.npmjs.org/"
|
|
40
41
|
},
|
|
41
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "152ccba46e781902f302b7adca1788a6909e9569"
|
|
42
43
|
}
|
|
@@ -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 };
|