@novlan/postcss-plugin-remove-selector 0.1.3 → 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 +79 -22
- package/lib/index.d.ts +3 -2
- package/lib/index.js +166 -87
- package/lib/plugin.d.ts +7 -3
- package/lib/presets.d.ts +8 -0
- package/lib/tdesign-uniapp-icon.d.ts +3 -4
- package/lib/types.d.ts +51 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -23,11 +23,47 @@
|
|
|
23
23
|
pnpm add @novlan/postcss-plugin-remove-selector -D
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
### 简化模式(推荐)
|
|
27
|
+
|
|
28
|
+
通过 `mode` 指定预设,只需关注 `used`/`unused`,无需手动配置 `file` 和 `selectorPattern`:
|
|
27
29
|
|
|
28
30
|
```ts
|
|
29
31
|
import { defineConfig } from 'vite';
|
|
30
|
-
import {
|
|
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` 数组传入完整配置,适用于需要匹配多个文件的复杂场景:
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import { defineConfig } from 'vite';
|
|
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: [
|
|
75
|
+
plugins: [postcssPluginRemoveSelector(TDESIGN_ICON_REMOVE_SELECTOR)],
|
|
40
76
|
},
|
|
41
77
|
},
|
|
42
78
|
});
|
|
@@ -44,25 +80,46 @@ export default defineConfig({
|
|
|
44
80
|
|
|
45
81
|
## 3. 类型
|
|
46
82
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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(标准模式)
|
|
101
|
+
|
|
102
|
+
| 属性 | 类型 | 是否必填 | 说明 |
|
|
103
|
+
| --- | --- | --- | --- |
|
|
104
|
+
| `list` | `FileConfig[]` | 是 | 配置列表 |
|
|
105
|
+
| `debug` | `boolean` | 否 | 是否开启调试模式 |
|
|
106
|
+
|
|
107
|
+
### FileConfig
|
|
108
|
+
|
|
109
|
+
| 属性 | 类型 | 是否必填 | 说明 |
|
|
110
|
+
| --- | --- | --- | --- |
|
|
111
|
+
| `file` | `RegExp \| string` | 是 | 文件匹配规则,可以是字符串或正则表达式 |
|
|
112
|
+
| `used` | `string[]` | 否 | 正在使用的图标名称列表,这些图标会被保留 |
|
|
113
|
+
| `unused` | `string[]` | 否 | 未使用的图标名称列表,这些图标会被移除 |
|
|
114
|
+
| `customUsed` | `string[]` | 否 | 增量追加到 `used` 列表(不覆盖已有的 `used`) |
|
|
115
|
+
| `customUnused` | `string[]` | 否 | 增量追加到 `unused` 列表(不覆盖已有的 `unused`) |
|
|
116
|
+
| `selectorPattern` | `RegExp` | 否 | 选择器匹配模式,只处理匹配该模式的选择器 |
|
|
117
|
+
|
|
118
|
+
### 内置预设
|
|
119
|
+
|
|
120
|
+
| mode | 说明 | 默认 file | 默认 selectorPattern |
|
|
121
|
+
| --- | --- | --- | --- |
|
|
122
|
+
| `tdesign` | TDesign UniApp 图标减包 | `/[@/]tdesign[/]uniapp[/]dist[/]icon[/]icon\.[css\|vue]/` | `/^\.t-icon-[\w-]+:before$/` |
|
|
66
123
|
|
|
67
124
|
## 4. 更新日志
|
|
68
125
|
|
package/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export * from './plugin';
|
|
2
|
-
export
|
|
3
|
-
export
|
|
2
|
+
export * from './tdesign-uniapp-icon';
|
|
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,
|
|
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
|
-
// 如果有
|
|
41
|
-
if (
|
|
42
|
-
return !
|
|
40
|
+
// 如果有 used 列表,只保留 used 中的图标
|
|
41
|
+
if (used.length) {
|
|
42
|
+
return !used.includes(iconName || '');
|
|
43
43
|
}
|
|
44
|
-
// 如果有
|
|
45
|
-
if (
|
|
46
|
-
return
|
|
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 {
|
|
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
|
-
|
|
71
|
-
|
|
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
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
-
|
|
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
|
-
|
|
109
|
-
|
|
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
|
}
|
|
@@ -118,72 +256,13 @@ catch (e) {
|
|
|
118
256
|
* TDesign UniApp 图标减包配置
|
|
119
257
|
*
|
|
120
258
|
* 使用说明:
|
|
121
|
-
* 1. 在
|
|
259
|
+
* 1. 在 TDESIGN_USED_ICONS 数组中配置项目中实际使用的图标名称
|
|
122
260
|
* 2. 插件只会处理 .t-icon-xxx:before 这类图标选择器
|
|
123
261
|
* 3. 其他基础样式(如 @font-face、.t-icon 等)会自动保留
|
|
124
262
|
*
|
|
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 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,19 +270,19 @@ const TDESIGN_ICON_REMOVE_SELECTOR = {
|
|
|
191
270
|
list: [
|
|
192
271
|
{
|
|
193
272
|
// 匹配 @tdesign/uniapp 的图标 css 文件
|
|
194
|
-
file:
|
|
273
|
+
file: PRESETS.tdesign.file,
|
|
195
274
|
// 只处理 .t-icon-xxx:before 这类图标选择器,其他样式自动保留
|
|
196
|
-
selectorPattern:
|
|
275
|
+
selectorPattern: PRESETS.tdesign.selectorPattern,
|
|
197
276
|
// 保留的图标名称列表
|
|
198
|
-
|
|
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["default"] =
|
|
284
|
+
exports["default"] = postcssPluginRemoveSelector;
|
|
206
285
|
exports.extractIconName = extractIconName;
|
|
207
|
-
exports.
|
|
286
|
+
exports.postcssPluginRemoveSelector = postcssPluginRemoveSelector;
|
|
208
287
|
exports.shouldHandleFile = shouldHandleFile;
|
|
209
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
|
|
15
|
-
export {
|
|
18
|
+
declare const postcssPluginRemoveSelector: any;
|
|
19
|
+
export { postcssPluginRemoveSelector };
|
package/lib/presets.d.ts
ADDED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* TDesign UniApp 图标减包配置
|
|
3
3
|
*
|
|
4
4
|
* 使用说明:
|
|
5
|
-
* 1. 在
|
|
5
|
+
* 1. 在 TDESIGN_USED_ICONS 数组中配置项目中实际使用的图标名称
|
|
6
6
|
* 2. 插件只会处理 .t-icon-xxx:before 这类图标选择器
|
|
7
7
|
* 3. 其他基础样式(如 @font-face、.t-icon 等)会自动保留
|
|
8
8
|
*
|
|
@@ -14,9 +14,8 @@
|
|
|
14
14
|
*/
|
|
15
15
|
export declare const TDESIGN_ICON_REMOVE_SELECTOR: {
|
|
16
16
|
list: {
|
|
17
|
-
file: RegExp;
|
|
17
|
+
file: string | RegExp;
|
|
18
18
|
selectorPattern: RegExp;
|
|
19
|
-
|
|
20
|
-
exclude: never[];
|
|
19
|
+
used: string[] | undefined;
|
|
21
20
|
}[];
|
|
22
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
|
-
|
|
9
|
-
/**
|
|
10
|
-
|
|
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
|
-
|
|
31
|
-
/**
|
|
32
|
-
|
|
72
|
+
/** 正在使用的选择器列表,这些会被保留 */
|
|
73
|
+
used: string[];
|
|
74
|
+
/** 未使用的选择器列表,这些会被移除 */
|
|
75
|
+
unused: string[];
|
|
33
76
|
/** 当前选择器 */
|
|
34
77
|
selector: string;
|
|
35
78
|
}
|
package/package.json
CHANGED