@novlan/postcss-plugin-remove-selector 0.1.4 → 0.1.5

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/README.md CHANGED
@@ -23,11 +23,47 @@
23
23
  pnpm add @novlan/postcss-plugin-remove-selector -D
24
24
  ```
25
25
 
26
- `vite.config.ts` 中使用:
26
+ ### 简化模式(推荐)
27
+
28
+ 通过 `mode` 指定预设,只需关注 `used`/`unused`,无需手动配置 `file` 和 `selectorPattern`:
29
+
30
+ ```ts
31
+ import { defineConfig } from 'vite';
32
+ import { postcssPluginRemoveSelector } from '@novlan/postcss-plugin-remove-selector';
33
+
34
+ export default defineConfig({
35
+ css: {
36
+ postcss: {
37
+ plugins: [
38
+ postcssPluginRemoveSelector({
39
+ mode: 'tdesign',
40
+ used: ['home', 'chat', 'user', 'add', 'search', 'close'],
41
+ }),
42
+ ],
43
+ },
44
+ },
45
+ });
46
+ ```
47
+
48
+ 使用 `customUsed` / `customUnused` 可在预设基础上增量追加,不会覆盖预设中已有的列表:
49
+
50
+ ```ts
51
+ postcssPluginRemoveSelector({
52
+ mode: 'tdesign',
53
+ // 在 tdesign 预设默认的 used 列表上,额外追加 'star' 和 'heart'
54
+ customUsed: ['star', 'heart'],
55
+ // 从结果中额外移除 'loading'
56
+ customUnused: ['loading'],
57
+ })
58
+ ```
59
+
60
+ ### 标准模式
61
+
62
+ 通过 `list` 数组传入完整配置,适用于需要匹配多个文件的复杂场景:
27
63
 
28
64
  ```ts
29
65
  import { defineConfig } from 'vite';
30
- import { postCssPluginRemoveSelector } from '@novlan/postcss-plugin-remove-selector';
66
+ import { postcssPluginRemoveSelector } from '@novlan/postcss-plugin-remove-selector';
31
67
  import {
32
68
  TDESIGN_ICON_REMOVE_SELECTOR
33
69
  } from '@novlan/postcss-plugin-remove-selector/lib/tdesign-uniapp-icon';
@@ -36,7 +72,7 @@ import {
36
72
  export default defineConfig({
37
73
  css: {
38
74
  postcss: {
39
- plugins: [postCssPluginRemoveSelector(TDESIGN_ICON_REMOVE_SELECTOR)],
75
+ plugins: [postcssPluginRemoveSelector(TDESIGN_ICON_REMOVE_SELECTOR)],
40
76
  },
41
77
  },
42
78
  });
@@ -44,7 +80,24 @@ export default defineConfig({
44
80
 
45
81
  ## 3. 类型
46
82
 
47
- ### Options
83
+ 插件支持两种配置方式,传入 `SimpleOptions`(简化模式)或 `Options`(标准模式)均可。
84
+
85
+ ### SimpleOptions(简化模式)
86
+
87
+ | 属性 | 类型 | 是否必填 | 说明 |
88
+ | --- | --- | --- | --- |
89
+ | `mode` | `'tdesign'` | 否 | 预设模式,设置后自动使用对应的 `file` 和 `selectorPattern` 默认值 |
90
+ | `file` | `RegExp \| string` | 否 | 文件匹配规则。使用 `mode` 时可省略 |
91
+ | `used` | `string[]` | 否 | 正在使用的图标名称列表,这些图标会被保留 |
92
+ | `unused` | `string[]` | 否 | 未使用的图标名称列表,这些图标会被移除 |
93
+ | `customUsed` | `string[]` | 否 | 增量追加到 `used` 列表(不覆盖预设或已有的 `used`) |
94
+ | `customUnused` | `string[]` | 否 | 增量追加到 `unused` 列表(不覆盖预设或已有的 `unused`) |
95
+ | `selectorPattern` | `RegExp` | 否 | 选择器匹配模式。使用 `mode` 时可省略 |
96
+ | `debug` | `boolean` | 否 | 是否开启调试模式 |
97
+
98
+ > `mode` 和 `file` 至少需要指定一个。当 `mode` 和 `file`/`selectorPattern` 同时指定时,`file`/`selectorPattern` 优先。
99
+
100
+ ### Options(标准模式)
48
101
 
49
102
  | 属性 | 类型 | 是否必填 | 说明 |
50
103
  | --- | --- | --- | --- |
@@ -56,10 +109,18 @@ export default defineConfig({
56
109
  | 属性 | 类型 | 是否必填 | 说明 |
57
110
  | --- | --- | --- | --- |
58
111
  | `file` | `RegExp \| string` | 是 | 文件匹配规则,可以是字符串或正则表达式 |
59
- | `include` | `string[]` | 否 | 需要保留的选择器列表(图标名称) |
60
- | `exclude` | `string[]` | 否 | 需要移除的选择器列表(图标名称) |
112
+ | `used` | `string[]` | 否 | 正在使用的图标名称列表,这些图标会被保留 |
113
+ | `unused` | `string[]` | 否 | 未使用的图标名称列表,这些图标会被移除 |
114
+ | `customUsed` | `string[]` | 否 | 增量追加到 `used` 列表(不覆盖已有的 `used`) |
115
+ | `customUnused` | `string[]` | 否 | 增量追加到 `unused` 列表(不覆盖已有的 `unused`) |
61
116
  | `selectorPattern` | `RegExp` | 否 | 选择器匹配模式,只处理匹配该模式的选择器 |
62
117
 
118
+ ### 内置预设
119
+
120
+ | mode | 说明 | 默认 file | 默认 selectorPattern |
121
+ | --- | --- | --- | --- |
122
+ | `tdesign` | TDesign UniApp 图标减包 | `/[@/]tdesign[/]uniapp[/]dist[/]icon[/]icon\.[css\|vue]/` | `/^\.t-icon-[\w-]+:before$/` |
123
+
63
124
  ## 4. 更新日志
64
125
 
65
126
  [点此查看](./CHANGELOG.md)
package/lib/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './plugin';
2
2
  export * from './tdesign-uniapp-icon';
3
- export { postCssPluginRemoveSelector as default } from './plugin';
3
+ export * from './presets';
4
+ export { postcssPluginRemoveSelector as default } from './plugin';
package/lib/index.js CHANGED
@@ -30,25 +30,154 @@ function extractIconName(selector) {
30
30
  * @param options 配置项
31
31
  */
32
32
  function shouldRemoveRule(options) {
33
- const { selectorPattern, include, exclude, selector } = options;
33
+ const { selectorPattern, used, unused, selector } = options;
34
34
  // 如果配置了 selectorPattern,只处理匹配的选择器
35
35
  if (selectorPattern && !selectorPattern.test(selector)) {
36
36
  return false;
37
37
  }
38
38
  // 提取图标名称进行精确匹配
39
39
  const iconName = extractIconName(selector);
40
- // 如果有 include 列表,只保留 include 中的图标
41
- if (include.length) {
42
- return !include.includes(iconName || '');
40
+ // 如果有 used 列表,只保留 used 中的图标
41
+ if (used.length) {
42
+ return !used.includes(iconName || '');
43
43
  }
44
- // 如果有 exclude 列表,移除 exclude 中的图标
45
- if (exclude.length) {
46
- return exclude.includes(iconName || '');
44
+ // 如果有 unused 列表,移除 unused 中的图标
45
+ if (unused.length) {
46
+ return unused.includes(iconName || '');
47
47
  }
48
48
  return false;
49
49
  }
50
50
 
51
+ const TDESIGN_USED_ICONS = [
52
+ // custom-tab-bar.vue
53
+ 'home',
54
+ 'chat',
55
+ 'user',
56
+ // home/index.vue
57
+ 'add',
58
+ // release/index.vue
59
+ 'location',
60
+ 'file-copy',
61
+ 'upload',
62
+ // search/index.vue
63
+ 'search',
64
+ 'delete',
65
+ // data-center/index.vue
66
+ 'info-circle-filled',
67
+ // my/index.vue - 静态图标
68
+ 'discount',
69
+ 'edit',
70
+ // my/index.vue - gridList 动态图标
71
+ 'root-list',
72
+ // my/index.vue - settingList 动态图标
73
+ 'service',
74
+ 'setting',
75
+ // setting/index.vue - menuData 动态图标
76
+ 'app',
77
+ 'notification',
78
+ 'image',
79
+ 'chart',
80
+ 'sound',
81
+ 'secured',
82
+ 'info-circle',
83
+ // login/login.vue
84
+ 'logo-wechat-stroke',
85
+ 'logo-qq',
86
+ 'logo-wecom',
87
+ 'caret-down-small',
88
+ // nav-bar.vue
89
+ 'view-list',
90
+ // 组件内部可能使用的图标(如 t-navbar left-arrow 等)
91
+ 'chevron-left',
92
+ 'chevron-right',
93
+ 'chevron-up',
94
+ 'chevron-down',
95
+ 'arrow-left',
96
+ 'arrow-right',
97
+ 'arrow-up',
98
+ 'arrow-down',
99
+ 'close',
100
+ 'close-circle-filled',
101
+ 'check',
102
+ 'check-circle-filled',
103
+ 'error-circle-filled',
104
+ 'loading',
105
+ ];
106
+ /**
107
+ * 内置预设配置
108
+ *
109
+ * 每个预设包含默认的 file 和 selectorPattern,
110
+ * 用户只需提供 include/exclude 即可快速使用
111
+ */
112
+ const PRESETS = {
113
+ tdesign: {
114
+ /** 匹配 @tdesign/uniapp 的图标 css 文件 */
115
+ file: /[@/]tdesign[/]uniapp[/]dist[/]icon[/]icon\.[css|vue]/,
116
+ /** 只处理 .t-icon-xxx:before 这类图标选择器 */
117
+ selectorPattern: /^\.t-icon-[\w-]+:before$/,
118
+ // 保留的图标名称列表
119
+ used: TDESIGN_USED_ICONS,
120
+ },
121
+ };
122
+
51
123
  const PLUGIN_NAME = 'postcss-plugin-remove-selector';
124
+ /**
125
+ * 判断传入的配置是否为简化模式
126
+ */
127
+ function isSimpleOptions(opts) {
128
+ return !('list' in opts);
129
+ }
130
+ /**
131
+ * 将简化配置转换为标准 Options
132
+ */
133
+ function normalizeOptions(opts) {
134
+ if (!isSimpleOptions(opts)) {
135
+ return opts;
136
+ }
137
+ const { mode, file, used, unused, customUsed, customUnused, selectorPattern, debug } = opts;
138
+ let resolvedFile = file;
139
+ let resolvedSelectorPattern = selectorPattern;
140
+ let resolvedUsed = used || [];
141
+ let resolvedUnused = unused || [];
142
+ // 如果指定了 mode,使用预设的默认值
143
+ if (mode && PRESETS[mode]) {
144
+ const preset = PRESETS[mode];
145
+ if (!resolvedFile) {
146
+ resolvedFile = preset.file;
147
+ }
148
+ if (!resolvedSelectorPattern) {
149
+ resolvedSelectorPattern = preset.selectorPattern;
150
+ }
151
+ // 如果用户没有显式指定 used/unused,使用预设的默认值
152
+ if (!used && preset.used) {
153
+ resolvedUsed = [...preset.used];
154
+ }
155
+ if (!unused && preset.unused) {
156
+ resolvedUnused = [...preset.unused];
157
+ }
158
+ }
159
+ // 将 customUsed/customUnused 增量追加(不覆盖)
160
+ if (customUsed?.length) {
161
+ resolvedUsed = [...resolvedUsed, ...customUsed];
162
+ }
163
+ if (customUnused?.length) {
164
+ resolvedUnused = [...resolvedUnused, ...customUnused];
165
+ }
166
+ if (!resolvedFile) {
167
+ throw new Error(`[${PLUGIN_NAME}] 必须指定 "file" 或 "mode",当前均未设置。`);
168
+ }
169
+ return {
170
+ list: [
171
+ {
172
+ file: resolvedFile,
173
+ used: resolvedUsed,
174
+ unused: resolvedUnused,
175
+ selectorPattern: resolvedSelectorPattern,
176
+ },
177
+ ],
178
+ debug,
179
+ };
180
+ }
52
181
  /**
53
182
  * 核心处理逻辑,PostCSS 7 / 8 共用
54
183
  */
@@ -59,7 +188,10 @@ function processRoot(root, result, opts) {
59
188
  if (!found) {
60
189
  return;
61
190
  }
62
- const { exclude = [], include = [], selectorPattern } = found;
191
+ const { used = [], unused = [], customUsed = [], customUnused = [], selectorPattern } = found;
192
+ // 合并 customUsed/customUnused 到 used/unused
193
+ const mergedUsed = customUsed.length ? [...used, ...customUsed] : used;
194
+ const mergedUnused = customUnused.length ? [...unused, ...customUnused] : unused;
63
195
  if (debug) {
64
196
  console.log('[postcss-plugin-remove-selector] handling:', fileName);
65
197
  }
@@ -67,8 +199,8 @@ function processRoot(root, result, opts) {
67
199
  root.walkRules((rule) => {
68
200
  if (shouldRemoveRule({
69
201
  selectorPattern,
70
- exclude,
71
- include,
202
+ used: mergedUsed,
203
+ unused: mergedUnused,
72
204
  selector: rule.selector,
73
205
  })) {
74
206
  rule.remove();
@@ -87,26 +219,32 @@ function processRoot(root, result, opts) {
87
219
  * - PostCSS 8:使用标准 Creator 函数格式 + postcss: true 标记
88
220
  * - PostCSS 7:回退到 postcss.plugin() 注册方式
89
221
  *
222
+ * 支持两种配置方式:
223
+ * 1. 标准模式:传入 { list: [...], debug?: boolean }
224
+ * 2. 简化模式:传入 { mode?, file?, used?, unused?, customUsed?, customUnused?, selectorPattern?, debug? }
225
+ *
90
226
  * @param opts 配置项
91
227
  * @returns PostCSS 插件
92
228
  */
93
- const postCssPluginRemoveSelector = (opts = { list: [] }) =>
94
- // PostCSS 8 格式
95
- ({
96
- postcssPlugin: PLUGIN_NAME,
97
- Once(root, { result }) {
98
- processRoot(root, result, opts);
99
- },
100
- });
229
+ const postcssPluginRemoveSelector = (opts = { list: [] }) => {
230
+ const normalizedOpts = normalizeOptions(opts);
231
+ return {
232
+ postcssPlugin: PLUGIN_NAME,
233
+ Once(root, { result }) {
234
+ processRoot(root, result, normalizedOpts);
235
+ },
236
+ };
237
+ };
101
238
  // 标记为 PostCSS 8 插件
102
- postCssPluginRemoveSelector.postcss = true;
239
+ postcssPluginRemoveSelector.postcss = true;
103
240
  // PostCSS 7 兼容:通过 postcss.plugin() 注册
104
241
  try {
105
242
  // eslint-disable-next-line @typescript-eslint/no-require-imports
106
243
  const postcss = require('postcss');
107
244
  if (postcss && typeof postcss.plugin === 'function') {
108
- postCssPluginRemoveSelector.postcss7 = postcss.plugin(PLUGIN_NAME, (opts = { list: [] }) => (root, result) => {
109
- processRoot(root, result, opts);
245
+ postcssPluginRemoveSelector.postcss7 = postcss.plugin(PLUGIN_NAME, (opts = { list: [] }) => (root, result) => {
246
+ const normalizedOpts = normalizeOptions(opts);
247
+ processRoot(root, result, normalizedOpts);
110
248
  });
111
249
  }
112
250
  }
@@ -125,65 +263,6 @@ catch (e) {
125
263
  * 如何查找项目中使用的图标:
126
264
  * grep -rho 'icon="[^"]*"\|left-icon="[^"]*"\|name="[^"]*"' src --include="*.vue" | sort | uniq
127
265
  */
128
- /**
129
- * 项目中实际使用的图标列表
130
- * 根据 src 目录下的 .vue 文件分析得出
131
- */
132
- const TDESIGN_USED_ICONS = [
133
- // custom-tab-bar.vue
134
- 'home',
135
- 'chat',
136
- 'user',
137
- // home/index.vue
138
- 'add',
139
- // release/index.vue
140
- 'location',
141
- 'file-copy',
142
- 'upload',
143
- // search/index.vue
144
- 'search',
145
- 'delete',
146
- // data-center/index.vue
147
- 'info-circle-filled',
148
- // my/index.vue - 静态图标
149
- 'discount',
150
- 'edit',
151
- // my/index.vue - gridList 动态图标
152
- 'root-list',
153
- // my/index.vue - settingList 动态图标
154
- 'service',
155
- 'setting',
156
- // setting/index.vue - menuData 动态图标
157
- 'app',
158
- 'notification',
159
- 'image',
160
- 'chart',
161
- 'sound',
162
- 'secured',
163
- 'info-circle',
164
- // login/login.vue
165
- 'logo-wechat-stroke',
166
- 'logo-qq',
167
- 'logo-wecom',
168
- 'caret-down-small',
169
- // nav-bar.vue
170
- 'view-list',
171
- // 组件内部可能使用的图标(如 t-navbar left-arrow 等)
172
- 'chevron-left',
173
- 'chevron-right',
174
- 'chevron-up',
175
- 'chevron-down',
176
- 'arrow-left',
177
- 'arrow-right',
178
- 'arrow-up',
179
- 'arrow-down',
180
- 'close',
181
- 'close-circle-filled',
182
- 'check',
183
- 'check-circle-filled',
184
- 'error-circle-filled',
185
- 'loading',
186
- ];
187
266
  /**
188
267
  * TDesign UniApp 图标减包配置
189
268
  */
@@ -191,20 +270,19 @@ const TDESIGN_ICON_REMOVE_SELECTOR = {
191
270
  list: [
192
271
  {
193
272
  // 匹配 @tdesign/uniapp 的图标 css 文件
194
- file: /[@/]tdesign[/]uniapp[/]dist[/]icon[/]icon\.[css|vue]/,
273
+ file: PRESETS.tdesign.file,
195
274
  // 只处理 .t-icon-xxx:before 这类图标选择器,其他样式自动保留
196
- selectorPattern: /^\.t-icon-[\w-]+:before$/,
275
+ selectorPattern: PRESETS.tdesign.selectorPattern,
197
276
  // 保留的图标名称列表
198
- include: TDESIGN_USED_ICONS,
199
- exclude: [],
277
+ used: PRESETS.tdesign.used,
200
278
  },
201
279
  ],
202
280
  };
203
281
 
282
+ exports.PRESETS = PRESETS;
204
283
  exports.TDESIGN_ICON_REMOVE_SELECTOR = TDESIGN_ICON_REMOVE_SELECTOR;
205
- exports.TDESIGN_USED_ICONS = TDESIGN_USED_ICONS;
206
- exports["default"] = postCssPluginRemoveSelector;
284
+ exports["default"] = postcssPluginRemoveSelector;
207
285
  exports.extractIconName = extractIconName;
208
- exports.postCssPluginRemoveSelector = postCssPluginRemoveSelector;
286
+ exports.postcssPluginRemoveSelector = postcssPluginRemoveSelector;
209
287
  exports.shouldHandleFile = shouldHandleFile;
210
288
  exports.shouldRemoveRule = shouldRemoveRule;
package/lib/plugin.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type { Options, FileConfig, ShouldRemoveRuleOptions } from './types';
1
+ export type { Options, SimpleOptions, FileConfig, ShouldRemoveRuleOptions, PresetMode, Preset } from './types';
2
2
  export { shouldHandleFile, shouldRemoveRule, extractIconName } from './helper';
3
3
  /**
4
4
  * PostCSS 插件:移除指定的 CSS 选择器
@@ -8,8 +8,12 @@ export { shouldHandleFile, shouldRemoveRule, extractIconName } from './helper';
8
8
  * - PostCSS 8:使用标准 Creator 函数格式 + postcss: true 标记
9
9
  * - PostCSS 7:回退到 postcss.plugin() 注册方式
10
10
  *
11
+ * 支持两种配置方式:
12
+ * 1. 标准模式:传入 { list: [...], debug?: boolean }
13
+ * 2. 简化模式:传入 { mode?, file?, used?, unused?, customUsed?, customUnused?, selectorPattern?, debug? }
14
+ *
11
15
  * @param opts 配置项
12
16
  * @returns PostCSS 插件
13
17
  */
14
- declare const postCssPluginRemoveSelector: any;
15
- export { postCssPluginRemoveSelector };
18
+ declare const postcssPluginRemoveSelector: any;
19
+ export { postcssPluginRemoveSelector };
@@ -0,0 +1,8 @@
1
+ import type { Preset, PresetMode } from './types';
2
+ /**
3
+ * 内置预设配置
4
+ *
5
+ * 每个预设包含默认的 file 和 selectorPattern,
6
+ * 用户只需提供 include/exclude 即可快速使用
7
+ */
8
+ export declare const PRESETS: Record<PresetMode, Preset>;
@@ -9,19 +9,13 @@
9
9
  * 如何查找项目中使用的图标:
10
10
  * grep -rho 'icon="[^"]*"\|left-icon="[^"]*"\|name="[^"]*"' src --include="*.vue" | sort | uniq
11
11
  */
12
- /**
13
- * 项目中实际使用的图标列表
14
- * 根据 src 目录下的 .vue 文件分析得出
15
- */
16
- export declare const TDESIGN_USED_ICONS: string[];
17
12
  /**
18
13
  * TDesign UniApp 图标减包配置
19
14
  */
20
15
  export declare const TDESIGN_ICON_REMOVE_SELECTOR: {
21
16
  list: {
22
- file: RegExp;
17
+ file: string | RegExp;
23
18
  selectorPattern: RegExp;
24
- include: string[];
25
- exclude: never[];
19
+ used: string[] | undefined;
26
20
  }[];
27
21
  };
package/lib/types.d.ts CHANGED
@@ -4,10 +4,14 @@
4
4
  export interface FileConfig {
5
5
  /** 文件匹配规则,可以是字符串或正则表达式 */
6
6
  file: RegExp | string;
7
- /** 需要保留的选择器列表(图标名称) */
8
- include?: string[];
9
- /** 需要移除的选择器列表(图标名称) */
10
- exclude?: string[];
7
+ /** 正在使用的选择器列表(图标名称),这些图标会被保留 */
8
+ used?: string[];
9
+ /** 未使用的选择器列表(图标名称),这些图标会被移除 */
10
+ unused?: string[];
11
+ /** 增量追加到 used 列表中的图标名称,不会覆盖已有的 used */
12
+ customUsed?: string[];
13
+ /** 增量追加到 unused 列表中的图标名称,不会覆盖已有的 unused */
14
+ customUnused?: string[];
11
15
  /** 选择器匹配模式,只处理匹配该模式的选择器 */
12
16
  selectorPattern?: RegExp;
13
17
  }
@@ -20,16 +24,55 @@ export interface Options {
20
24
  /** 是否开启调试模式 */
21
25
  debug?: boolean;
22
26
  }
27
+ /**
28
+ * 预设模式名称
29
+ */
30
+ export type PresetMode = 'tdesign';
31
+ /**
32
+ * 预设配置,包含默认的 file 和 selectorPattern
33
+ */
34
+ export interface Preset {
35
+ /** 文件匹配规则 */
36
+ file: RegExp | string;
37
+ /** 选择器匹配模式 */
38
+ selectorPattern: RegExp;
39
+ /** 正在使用的选择器列表(图标名称),这些图标会被保留 */
40
+ used?: string[];
41
+ /** 未使用的选择器列表(图标名称),这些图标会被移除 */
42
+ unused?: string[];
43
+ }
44
+ /**
45
+ * 简化配置项(扁平化形式)
46
+ * 适用于只需要配置单个文件场景,无需传递 list 数组
47
+ */
48
+ export interface SimpleOptions {
49
+ /** 预设模式,如 'tdesign',设置后自动使用对应的 file 和 selectorPattern 默认值 */
50
+ mode?: PresetMode;
51
+ /** 文件匹配规则,可以是字符串或正则表达式。使用 mode 时可省略 */
52
+ file?: RegExp | string;
53
+ /** 正在使用的选择器列表(图标名称),这些图标会被保留 */
54
+ used?: string[];
55
+ /** 未使用的选择器列表(图标名称),这些图标会被移除 */
56
+ unused?: string[];
57
+ /** 增量追加到 used 列表中的图标名称,不会覆盖已有的 used(适用于在预设基础上额外新增) */
58
+ customUsed?: string[];
59
+ /** 增量追加到 unused 列表中的图标名称,不会覆盖已有的 unused(适用于在预设基础上额外新增) */
60
+ customUnused?: string[];
61
+ /** 选择器匹配模式,只处理匹配该模式的选择器。使用 mode 时可省略 */
62
+ selectorPattern?: RegExp;
63
+ /** 是否开启调试模式 */
64
+ debug?: boolean;
65
+ }
23
66
  /**
24
67
  * 判断是否移除规则的参数
25
68
  */
26
69
  export interface ShouldRemoveRuleOptions {
27
70
  /** 选择器匹配模式 */
28
71
  selectorPattern?: RegExp;
29
- /** 需要保留的选择器列表 */
30
- include: string[];
31
- /** 需要移除的选择器列表 */
32
- exclude: string[];
72
+ /** 正在使用的选择器列表,这些会被保留 */
73
+ used: string[];
74
+ /** 未使用的选择器列表,这些会被移除 */
75
+ unused: string[];
33
76
  /** 当前选择器 */
34
77
  selector: string;
35
78
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@novlan/postcss-plugin-remove-selector",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "homepage": "https://novlan1.github.io/plugins/zh/postcss-plugin-remove-selector.html",
5
5
  "bugs": {
6
6
  "url": "https://github.com/novlan1/plugins/issues"