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 { }
|