css2class 2.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.
Files changed (57) hide show
  1. package/API.md +1143 -0
  2. package/CHANGELOG.md +291 -0
  3. package/CONFIG.md +1096 -0
  4. package/CONTRIBUTING.md +571 -0
  5. package/MIGRATION.md +402 -0
  6. package/README.md +634 -0
  7. package/bin/class2css.js +380 -0
  8. package/class2css.config.js +124 -0
  9. package/common.css +3 -0
  10. package/configs/colors.config.js +62 -0
  11. package/configs/layout.config.js +110 -0
  12. package/configs/spacing.config.js +37 -0
  13. package/configs/typography.config.js +41 -0
  14. package/docs/.vitepress/config.mjs +65 -0
  15. package/docs/.vitepress/theme/custom.css +74 -0
  16. package/docs/.vitepress/theme/index.js +7 -0
  17. package/docs/guide/cli.md +97 -0
  18. package/docs/guide/concepts.md +63 -0
  19. package/docs/guide/config-template.md +365 -0
  20. package/docs/guide/config.md +275 -0
  21. package/docs/guide/faq.md +202 -0
  22. package/docs/guide/getting-started.md +83 -0
  23. package/docs/guide/important-and-static.md +67 -0
  24. package/docs/guide/incremental.md +162 -0
  25. package/docs/guide/rules-reference.md +354 -0
  26. package/docs/guide/units.md +57 -0
  27. package/docs/index.md +68 -0
  28. package/package.json +49 -0
  29. package/run.js +90 -0
  30. package/src/README.md +571 -0
  31. package/src/core/CacheManager.js +650 -0
  32. package/src/core/CompatibilityAdapter.js +264 -0
  33. package/src/core/ConfigManager.js +431 -0
  34. package/src/core/ConfigValidator.js +350 -0
  35. package/src/core/EventBus.js +77 -0
  36. package/src/core/FullScanManager.js +430 -0
  37. package/src/core/StateManager.js +631 -0
  38. package/src/docs/DocsServer.js +179 -0
  39. package/src/example.js +106 -0
  40. package/src/generators/DynamicClassGenerator.js +674 -0
  41. package/src/index.js +1046 -0
  42. package/src/parsers/ClassParser.js +572 -0
  43. package/src/parsers/ImportantParser.js +279 -0
  44. package/src/parsers/RegexCompiler.js +200 -0
  45. package/src/utils/ClassChangeTracker.js +366 -0
  46. package/src/utils/ConfigDiagnostics.js +673 -0
  47. package/src/utils/CssFormatter.js +261 -0
  48. package/src/utils/FileUtils.js +230 -0
  49. package/src/utils/Logger.js +150 -0
  50. package/src/utils/Throttle.js +172 -0
  51. package/src/utils/UnitProcessor.js +334 -0
  52. package/src/utils/WxssClassExtractor.js +137 -0
  53. package/src/watchers/ConfigWatcher.js +413 -0
  54. package/src/watchers/FileWatcher.js +133 -0
  55. package/src/writers/FileWriter.js +302 -0
  56. package/src/writers/UnifiedWriter.js +370 -0
  57. package/styles.config.js +250 -0
@@ -0,0 +1,365 @@
1
+ # 配置模板(可复制)
2
+
3
+ 本页把仓库里的 `class2css.config.js`(你现在已经跑通、并且覆盖了当前支持能力)整理成一份**可直接复制**的模板,避免开发者每个项目都从零拼配置。
4
+
5
+ :::tip 配置结构说明
6
+ 配置已拆分为两个文件:
7
+ - **`class2css.config.js`**:工具运行配置(系统设置、输出路径等)
8
+ - **`styles.config.js`**:样式规则配置(原子化规则、基础类、变体、断点等)
9
+
10
+ 样式规则配置会自动从 `styles.config.js` 引入,无需手动合并。
11
+ :::
12
+
13
+ :::warning 先改 3 个地方就能跑
14
+ - `output.path` / `output.fileName`:输出位置与文件名
15
+ - `multiFile.entry.path`:要扫描/监听的源码目录(也支持写成数组,用于多目录/多文件入口)
16
+ - `multiFile.output.path` / `multiFile.output.fileName`:统一输出文件位置(`cssOutType='uniFile'` 时)
17
+ :::
18
+
19
+ ## 工具配置文件(class2css.config.js)
20
+
21
+ ```js
22
+ // ========== 工具配置文件 ==========
23
+ // 此文件包含工具运行相关的配置(系统设置、输出路径等)
24
+ // 样式规则配置请查看 styles.config.js
25
+
26
+ // 引入样式规则配置
27
+ const stylesConfig = require('./styles.config.js');
28
+
29
+ const config = {
30
+ // ========== 系统基础配置 ==========
31
+ system: {
32
+ // CSS 输出格式: 'multiLine' | 'singleLine' | 'compressed'
33
+ cssFormat: 'compressed',
34
+ // 基础单位设置
35
+ baseUnit: 'rpx',
36
+ // 单位转换比例:生成样式单位 = 设置单位 × 比例
37
+ unitConversion: 2,
38
+ // 是否压缩CSS
39
+ compression: true,
40
+ // 是否对生成的CSS类进行字母排序(按选择器名称)
41
+ sortClasses: true,
42
+ // 智能单位处理策略(保留配置入口,具体逻辑以当前版本实现为准)
43
+ unitStrategy: {
44
+ autoDetect: true,
45
+ propertyUnits: {
46
+ 'font-size': 'rpx',
47
+ 'width|height': 'rpx',
48
+ opacity: '',
49
+ 'z-index': '',
50
+ 'line-height': '',
51
+ 'border-radius': 'rpx',
52
+ },
53
+ },
54
+ },
55
+
56
+ // ========== 输出配置(单文件/非 multiFile 时) ==========
57
+ output: {
58
+ // 输出目录(建议用相对路径,或自行改成绝对路径)
59
+ path: './dist',
60
+ // 输出文件名
61
+ fileName: 'styles.wxss',
62
+ // 共用CSS文件路径(可选)
63
+ commonCssPath: './common.css',
64
+ },
65
+
66
+ // ========== Important 标识配置(从样式配置引入) ==========
67
+ importantFlags: stylesConfig.importantFlags,
68
+
69
+ // ========== 多文件构建(推荐) ==========
70
+ // 如果存在该字段,则以 multiFile.output 为准(覆盖 output.path/fileName 等单文件输出)
71
+ multiFile: {
72
+ entry: {
73
+ // 扫描/监听入口:
74
+ // - string:单目录/单文件
75
+ // - string[]:多目录/多文件(目录与文件可混用)
76
+ //
77
+ // 例如:
78
+ // path: ['./src', './subpackages', './pages/index.wxml'],
79
+ path: './src',
80
+ // 文件类型(WXML/HTML)
81
+ fileType: ['html', 'wxml'],
82
+ },
83
+ output: {
84
+ // filePath:将css文件导出到监听文件对应目录并生成同名样式文件
85
+ // uniFile:将所有样式导出到单文件
86
+ cssOutType: 'uniFile',
87
+ // 输出目录(cssOutType=uniFile 时生效)
88
+ path: './dist',
89
+ // 输出文件名(cssOutType=uniFile 时生效)
90
+ fileName: 'index.wxss',
91
+ // 输出文件扩展名(cssOutType=filePath 时生效)
92
+ fileType: 'wxss',
93
+
94
+ // ========== 增量模式(只增不删) ==========
95
+ incrementalOnlyAdd: true,
96
+ incrementalBaseline: 'fromOutputFile',
97
+ rebuildOnStart: true,
98
+ unusedReportLimit: 200,
99
+
100
+ // ========== uniFile 写入策略 ==========
101
+ // 'rewrite' | 'appendDelta'
102
+ // 注意:appendDelta 要求 rebuildOnStart=true
103
+ uniFileWriteMode: 'appendDelta',
104
+ },
105
+ },
106
+
107
+ // ========== 样式规则配置(从 styles.config.js 引入) ==========
108
+ atomicRules: stylesConfig.atomicRules,
109
+ baseClassName: stylesConfig.baseClassName,
110
+ variants: stylesConfig.variants,
111
+ breakpoints: stylesConfig.breakpoints,
112
+ };
113
+
114
+ function getConfig() {
115
+ return config;
116
+ }
117
+
118
+ module.exports = getConfig();
119
+ ```
120
+
121
+ ## 样式规则配置文件(styles.config.js)
122
+
123
+ 样式规则配置文件包含所有样式解析相关的配置:
124
+
125
+ ```js
126
+ // ========== 样式规则配置文件 ==========
127
+ // 此文件包含所有样式解析规则配置,与工具配置分离
128
+
129
+ // ========== 原子化规则配置 ==========
130
+ const atomicRules = {
131
+ "spacing": {
132
+ "m": { "properties": ["margin"], "defaultUnit": "rpx" },
133
+ "mt": { "properties": ["margin-top"], "defaultUnit": "rpx" },
134
+ "mr": { "properties": ["margin-right"], "defaultUnit": "rpx" },
135
+ "mb": { "properties": ["margin-bottom"], "defaultUnit": "rpx" },
136
+ "ml": { "properties": ["margin-left"], "defaultUnit": "rpx" },
137
+ "mx": { "properties": ["margin-left", "margin-right"], "defaultUnit": "rpx" },
138
+ "my": { "properties": ["margin-top", "margin-bottom"], "defaultUnit": "rpx" },
139
+ "p": { "properties": ["padding"], "defaultUnit": "rpx" },
140
+ "pt": { "properties": ["padding-top"], "defaultUnit": "rpx" },
141
+ "pr": { "properties": ["padding-right"], "defaultUnit": "rpx" },
142
+ "pb": { "properties": ["padding-bottom"], "defaultUnit": "rpx" },
143
+ "pl": { "properties": ["padding-left"], "defaultUnit": "rpx" },
144
+ "px": { "properties": ["padding-left", "padding-right"], "defaultUnit": "rpx" },
145
+ "py": { "properties": ["padding-top", "padding-bottom"], "defaultUnit": "rpx" },
146
+ "gap": { "properties": ["gap"], "defaultUnit": "rpx" }
147
+ },
148
+ "sizing": {
149
+ "w": { "properties": ["width"], "defaultUnit": "rpx" },
150
+ "h": { "properties": ["height"], "defaultUnit": "rpx" },
151
+ "max-w": { "properties": ["max-width"], "defaultUnit": "rpx" },
152
+ "max-h": { "properties": ["max-height"], "defaultUnit": "rpx" },
153
+ "min-w": { "properties": ["min-width"], "defaultUnit": "rpx" },
154
+ "min-h": { "properties": ["min-height"], "defaultUnit": "rpx" },
155
+ "size": { "properties": ["width", "height"], "defaultUnit": "rpx" }
156
+ },
157
+ "typography": {
158
+ "text-size": { "properties": ["font-size"], "defaultUnit": "rpx" },
159
+ "text": { "properties": ["font-size"], "defaultUnit": "rpx" },
160
+ "font": { "properties": ["font-weight"], "defaultUnit": "" },
161
+ "leading": { "properties": ["line-height"], "defaultUnit": "" },
162
+ "tracking": { "properties": ["letter-spacing"], "defaultUnit": "rpx" }
163
+ },
164
+ "positioning": {
165
+ "top": { "properties": ["top"], "defaultUnit": "rpx" },
166
+ "right": { "properties": ["right"], "defaultUnit": "rpx" },
167
+ "bottom": { "properties": ["bottom"], "defaultUnit": "rpx" },
168
+ "left": { "properties": ["left"], "defaultUnit": "rpx" },
169
+ "inset": { "properties": ["top", "right", "bottom", "left"], "defaultUnit": "rpx" },
170
+ "inset-x": { "properties": ["left", "right"], "defaultUnit": "rpx" },
171
+ "inset-y": { "properties": ["top", "bottom"], "defaultUnit": "rpx" }
172
+ },
173
+ "borders": {
174
+ "rounded": { "properties": ["border-radius"], "defaultUnit": "rpx" },
175
+ "border": { "properties": ["border-width"], "defaultUnit": "rpx" },
176
+ "bordert": { "properties": ["border-top-width"], "defaultUnit": "rpx" },
177
+ "borderr": { "properties": ["border-right-width"], "defaultUnit": "rpx" },
178
+ "borderb": { "properties": ["border-bottom-width"], "defaultUnit": "rpx" },
179
+ "borderl": { "properties": ["border-left-width"], "defaultUnit": "rpx" },
180
+ "b_r": { "properties": ["border-radius"], "defaultUnit": "rpx" }
181
+ },
182
+ "effects": {
183
+ "opacity": { "properties": ["opacity"], "defaultUnit": "" },
184
+ "transition": { "properties": ["transition"], "defaultUnit": "ms", "skipConversion": true },
185
+ "op": { "properties": ["opacity"], "defaultUnit": "" },
186
+ "z": { "properties": ["z-index"], "defaultUnit": "" }
187
+ }
188
+ },
189
+
190
+ // ========== Tailwind 风格静态 class ==========
191
+ // 这里保留“结构”,颜色表建议按自己项目裁剪
192
+ baseClassName: {
193
+ "color": { "ABBR": "color" },
194
+ "bg": { "ABBR": "background-color" },
195
+ "bcolor": { "ABBR": "border-color" },
196
+ "block": "display: block;",
197
+ "inline": "display: inline;",
198
+ "inline-block": "display: inline-block;",
199
+ "flex": "display: flex;",
200
+ "flex-1": "flex: 1;",
201
+ "shrink-0": "flex-shrink: 0;",
202
+ "inline-flex": "display: inline-flex;",
203
+ "grid": "display: grid;",
204
+ "inline-grid": "display: inline-grid;",
205
+ "table": "display: table;",
206
+ "hidden": "display: none;",
207
+ "w-full": "width: 100%;",
208
+ "h-full": "height: 100%;",
209
+ "w-screen": "width: 100vw;",
210
+ "h-screen": "height: 100vh;",
211
+ "flex-cen": "align-items: center;justify-content: center;",
212
+ "flex-row": "flex-direction: row;",
213
+ "flex-col": "flex-direction: column;",
214
+ "flex-wrap": "flex-wrap: wrap;",
215
+ "flex-nowrap": "flex-wrap: nowrap;",
216
+ "items-start": "align-items: flex-start;",
217
+ "items-center": "align-items: center;",
218
+ "items-end": "align-items: flex-end;",
219
+ "items-stretch": "align-items: stretch;",
220
+ "justify-start": "justify-content: flex-start;",
221
+ "justify-center": "justify-content: center;",
222
+ "justify-end": "justify-content: flex-end;",
223
+ "justify-between": "justify-content: space-between;",
224
+ "justify-around": "justify-content: space-around;",
225
+ "justify-evenly": "justify-content: space-evenly;",
226
+ "grid-cols-2": "grid-template-columns: repeat(2, 1fr);",
227
+ "grid-cols-3": "grid-template-columns: repeat(3, 1fr);",
228
+ "grid-cols-4": "grid-template-columns: repeat(4, 1fr);",
229
+ "static": "position: static;",
230
+ "fixed": "position: fixed;",
231
+ "absolute": "position: absolute;",
232
+ "relative": "position: relative;",
233
+ "sticky": "position: sticky;",
234
+ "overflow-auto": "overflow: auto;",
235
+ "overflow-hidden": "overflow: hidden;",
236
+ "overflow-visible": "overflow: visible;",
237
+ "overflow-scroll": "overflow: scroll;",
238
+ "underline": "text-decoration: underline;",
239
+ "line-through": "text-decoration: line-through;",
240
+ "ellipsis": "overflow: hidden;text-overflow: ellipsis;white-space: nowrap;",
241
+ "text-left": "text-align: left;",
242
+ "text-center": "text-align: center;",
243
+ "text-right": "text-align: right;",
244
+ "text-justify": "text-align: justify;",
245
+ "cursor-auto": "cursor: auto;",
246
+ "cursor-default": "cursor: default;",
247
+ "cursor-pointer": "cursor: pointer;",
248
+ "cursor-wait": "cursor: wait;",
249
+ "cursor-text": "cursor: text;",
250
+ "cursor-move": "cursor: move;",
251
+ "cursor-not-allowed": "cursor: not-allowed;",
252
+ "box-border": "box-sizing: border-box;",
253
+ "box-content": "box-sizing: content-box;",
254
+ "border-solid": "border-style: solid;",
255
+ "border-dashed": "border-style: dashed;",
256
+ "border-dotted": "border-style: dotted;",
257
+ "border-none": "border: none;"
258
+ },
259
+
260
+ // ========== 变体规则(响应式、伪类等) ==========
261
+ const variants = {
262
+ "responsive": ["sm", "md", "lg", "xl", "2xl"],
263
+ "states": ["hover", "focus", "active", "disabled", "first", "last", "odd", "even"],
264
+ "darkMode": ["dark"]
265
+ };
266
+
267
+ // ========== 响应式断点配置(可选) ==========
268
+ // 如果不配置,将使用默认 Tailwind 断点值
269
+ const breakpoints = {
270
+ sm: '640px', // 小屏幕(手机横屏)
271
+ md: '768px', // 中等屏幕(平板)
272
+ lg: '1024px', // 大屏幕(笔记本)
273
+ xl: '1280px', // 超大屏幕(桌面)
274
+ '2xl': '1536px' // 超超大屏幕(大桌面)
275
+ };
276
+
277
+ // ========== 颜色配置 ==========
278
+ const baseColor = {
279
+ white: '#ffffff',
280
+ black: '#000000',
281
+ transparent: 'transparent',
282
+ gray: '#6b7280',
283
+ red: '#ef4444',
284
+ green: '#22c55e',
285
+ sky: '#0ea5e9',
286
+ violet: '#8b5cf6',
287
+ };
288
+
289
+ // ========== Important标识配置 ==========
290
+ const importantFlags = {
291
+ // prefix: ['!', '$$'], // 前缀标识: !w-100, $$w-100
292
+ suffix: ['-i', '_i'], // 后缀标识: w-100_i, w-100-i
293
+ // custom: ['--important', '##IMP##'] // 自定义标识
294
+ };
295
+
296
+ // 处理颜色配置:将 baseColor 合并到 baseClassName 中具有 ABBR 属性的项
297
+ function processStyles() {
298
+ const processedBaseClassName = { ...baseClassName };
299
+
300
+ // 将颜色配置合并到具有 ABBR 的类中
301
+ Object.values(processedBaseClassName).forEach((item) => {
302
+ if (item && item.ABBR) {
303
+ Object.assign(item, baseColor);
304
+ }
305
+ });
306
+
307
+ return {
308
+ atomicRules,
309
+ baseClassName: processedBaseClassName,
310
+ variants,
311
+ breakpoints,
312
+ importantFlags,
313
+ };
314
+ }
315
+
316
+ module.exports = processStyles();
317
+ ```
318
+
319
+ ## 响应式设计示例
320
+
321
+ 使用响应式前缀可以轻松实现移动优先的响应式布局:
322
+
323
+ ```html
324
+ <!-- 响应式宽度 -->
325
+ <view class="w-full sm:w-100 md:w-200 lg:w-300">
326
+ <!-- 默认 100%,小屏 100rpx,中屏 200rpx,大屏 300rpx -->
327
+ </view>
328
+
329
+ <!-- 响应式显示/隐藏 -->
330
+ <view class="hidden sm:block">
331
+ <!-- 默认隐藏,小屏及以上显示 -->
332
+ </view>
333
+
334
+ <!-- 响应式间距 -->
335
+ <view class="m-10 sm:m-20 md:m-30">
336
+ <!-- 响应式外边距 -->
337
+ </view>
338
+
339
+ <!-- 响应式字体 -->
340
+ <text class="text-14 sm:text-16 md:text-18 lg:text-20">
341
+ <!-- 响应式字号 -->
342
+ </text>
343
+ ```
344
+
345
+ 生成的 CSS:
346
+
347
+ ```css
348
+ .w-full { width: 100%; }
349
+ @media (min-width: 640px) {
350
+ .sm\:w-100 { width: 200rpx; }
351
+ }
352
+ @media (min-width: 768px) {
353
+ .md\:w-200 { width: 400rpx; }
354
+ }
355
+ @media (min-width: 1024px) {
356
+ .lg\:w-300 { width: 600rpx; }
357
+ }
358
+ ```
359
+
360
+ ## 下一步
361
+
362
+ - 想了解“只增不删”与 `appendDelta`:阅读 [增量模式(只增不删)](./incremental.md)
363
+ - 想理解单位逻辑:阅读 [单位与转换策略](./units.md)
364
+ - 想查当前已内置的类名规则:阅读 [规则参考](./rules-reference.md)
365
+
@@ -0,0 +1,275 @@
1
+ # 配置指南
2
+
3
+ Class2CSS 通过 `class2css.config.js` 文件进行配置。配置文件支持新旧两种格式,完全向后兼容。
4
+
5
+ :::tip 阅读方式
6
+ 如果你想“避免重复配置”,直接复制: [配置模板(可复制)](./config-template.md)。
7
+ 如果你刚开始用,建议先看 [快速开始](./getting-started.md) 跑通一次;再回到本页把配置补全(单位策略/排序/多文件/增量)。
8
+ :::
9
+
10
+ ## 配置文件位置
11
+
12
+ 默认配置文件路径:`./class2css.config.js`
13
+
14
+ 可以通过 CLI 参数 `-c, --config` 指定自定义路径。
15
+
16
+ ## 最小配置(可运行)
17
+
18
+ ```js
19
+ module.exports = {
20
+ system: { baseUnit: 'rpx', unitConversion: 2, cssFormat: 'compressed' },
21
+ output: { path: '../dist', fileName: 'styles.wxss' },
22
+ cssName: {
23
+ m: { classArr: ['margin'], unit: 'rpx' },
24
+ w: { classArr: ['width'], unit: 'rpx' },
25
+ h: { classArr: ['height'], unit: 'rpx' },
26
+ },
27
+ };
28
+ ```
29
+
30
+ ## 配置结构
31
+
32
+ ### 新版配置结构(推荐)
33
+
34
+ 新版本引入了 `system` 配置节,提供更强大的功能:
35
+
36
+ ```javascript
37
+ module.exports = {
38
+ // ========== 系统基础配置 ==========
39
+ system: {
40
+ // CSS 输出格式: 'multiLine' | 'singleLine' | 'compressed'
41
+ cssFormat: "compressed",
42
+ // 基础单位设置
43
+ baseUnit: "rpx",
44
+ // 单位转换比例 生成样式单位=设置单位*比例
45
+ unitConversion: 2,
46
+ // 是否压缩CSS
47
+ compression: true,
48
+ // 是否对生成的CSS类进行字母排序(按选择器名称)
49
+ sortClasses: true,
50
+ // 智能单位处理策略
51
+ unitStrategy: {
52
+ autoDetect: true,
53
+ propertyUnits: {
54
+ 'font-size': 'rpx',
55
+ 'width|height': 'rpx',
56
+ 'opacity': '',
57
+ 'z-index': '',
58
+ 'line-height': '',
59
+ 'border-radius': 'rpx'
60
+ }
61
+ }
62
+ },
63
+
64
+ // ========== 输出配置 ==========
65
+ output: {
66
+ path: "../dist",
67
+ fileName: "styles.wxss"
68
+ },
69
+
70
+ // ========== CSS类映射 ==========
71
+ cssName: {
72
+ "m": { classArr: ["margin"], unit: "rpx" },
73
+ "w": { classArr: ["width"], unit: "rpx" },
74
+ "h": { classArr: ["height"], unit: "rpx" }
75
+ },
76
+
77
+ // ========== 静态类配置 ==========
78
+ baseClassName: {
79
+ "container": "max-width: 1200rpx; margin: 0 auto;",
80
+ "flex": "display: flex;"
81
+ }
82
+ };
83
+ ```
84
+
85
+ ### 向后兼容
86
+
87
+ 工具完全兼容旧版配置格式:
88
+
89
+ ```javascript
90
+ // 旧版配置仍然有效
91
+ module.exports = {
92
+ baseUnit: "rpx", // 自动映射到 system.baseUnit
93
+ unitConversion: 2, // 自动映射到 system.unitConversion
94
+ output: { /* ... */ },
95
+ cssName: { /* ... */ },
96
+ baseClassName: { /* ... */ }
97
+ };
98
+ ```
99
+
100
+ ## 配置项说明
101
+
102
+ ### system 配置
103
+
104
+ #### cssFormat
105
+
106
+ CSS 输出格式,可选值:
107
+ - `'multiLine'`:多行格式(每个规则占一行)
108
+ - `'singleLine'`:单行格式
109
+ - `'compressed'`:压缩格式(默认)
110
+
111
+ #### baseUnit
112
+
113
+ 基础单位设置,默认 `'rpx'`。
114
+
115
+ #### unitConversion
116
+
117
+ 单位转换比例,默认 `2`。
118
+ 生成样式单位 = 设置单位 × 比例
119
+
120
+ 例如:`unitConversion: 2` 时,`m-10` 会生成 `margin: 20rpx;`
121
+
122
+ #### compression
123
+
124
+ 是否压缩CSS,默认 `true`。
125
+
126
+ #### sortClasses
127
+
128
+ 是否对生成的CSS类进行字母排序(按选择器名称),默认 `false`。
129
+
130
+ #### unitStrategy
131
+
132
+ 智能单位处理策略:
133
+
134
+ ```javascript
135
+ unitStrategy: {
136
+ // 自动检测:如果用户写了单位,保持原单位;如果没写,使用默认单位
137
+ autoDetect: true,
138
+ // 属性默认单位映射
139
+ propertyUnits: {
140
+ 'font-size': 'rpx',
141
+ 'width|height': 'rpx',
142
+ 'opacity': '',
143
+ 'z-index': '',
144
+ 'line-height': '',
145
+ 'border-radius': 'rpx'
146
+ }
147
+ }
148
+ ```
149
+
150
+ 也可以先阅读概念页:[单位与转换策略](./units.md)。
151
+
152
+ ### output 配置
153
+
154
+ #### path
155
+
156
+ 输出文件目录路径。
157
+
158
+ #### fileName
159
+
160
+ 输出文件名(包含扩展名)。
161
+
162
+ #### commonCssPath(可选)
163
+
164
+ 公共基础样式文件路径(如果你希望每次输出都带上一段统一的基础 CSS)。
165
+
166
+ ### cssName 配置
167
+
168
+ CSS类映射,定义类名到CSS属性的映射关系:
169
+
170
+ ```javascript
171
+ cssName: {
172
+ "m": { classArr: ["margin"], unit: "rpx" },
173
+ "mt": { classArr: ["margin-top"], unit: "rpx" },
174
+ "w": { classArr: ["width"], unit: "rpx" },
175
+ "h": { classArr: ["height"], unit: "rpx" }
176
+ }
177
+ ```
178
+
179
+ ### baseClassName 配置
180
+
181
+ 静态类配置,定义预定义的CSS类:
182
+
183
+ ```javascript
184
+ baseClassName: {
185
+ "container": "max-width: 1200rpx; margin: 0 auto;",
186
+ "flex": "display: flex;",
187
+ "flex-center": "display: flex; justify-content: center; align-items: center;"
188
+ }
189
+ ```
190
+
191
+ 也可以阅读概念页:[Important 与静态类](./important-and-static.md)。
192
+
193
+ ### multiFile 配置(多文件模式)
194
+
195
+ 用于多文件构建和增量模式:
196
+
197
+ ```javascript
198
+ multiFile: {
199
+ entry: {
200
+ path: "./src",
201
+ fileType: ["wxml", "html"],
202
+ },
203
+ output: {
204
+ cssOutType: "uniFile",
205
+ path: "./dist",
206
+ fileName: "styles.wxss",
207
+
208
+ // 增量模式配置
209
+ incrementalOnlyAdd: true,
210
+ incrementalBaseline: "fromOutputFile",
211
+ rebuildOnStart: true,
212
+ unusedReportLimit: 200,
213
+
214
+ // 统一文件写入策略
215
+ uniFileWriteMode: "appendDelta",
216
+ },
217
+ }
218
+ ```
219
+
220
+ 详细说明请参考 [增量模式](./incremental.md)。
221
+
222
+ ### importantFlags 配置
223
+
224
+ Important标识配置:
225
+
226
+ ```javascript
227
+ importantFlags: {
228
+ suffix: ['-i', '_i'], // 后缀标识: w-100_i, w-100-i
229
+ }
230
+ ```
231
+
232
+ ## 配置模块化
233
+
234
+ 将大型配置拆分为多个模块:
235
+
236
+ ```javascript
237
+ // configs/spacing.config.js
238
+ module.exports = {
239
+ margin: {
240
+ "m": { classArr: ["margin"], unit: "rpx" },
241
+ "mt": { classArr: ["margin-top"], unit: "rpx" }
242
+ }
243
+ };
244
+
245
+ // class2css.config.js
246
+ const spacing = require('./configs/spacing.config');
247
+
248
+ module.exports = {
249
+ system: { /* ... */ },
250
+ cssName: {
251
+ ...spacing.margin,
252
+ // 其他配置
253
+ }
254
+ };
255
+ ```
256
+
257
+ ## 配置验证
258
+
259
+ 使用内置诊断工具检查配置健康状况:
260
+
261
+ ```javascript
262
+ const ConfigDiagnostics = require('class2css/src/utils/ConfigDiagnostics');
263
+
264
+ const diagnostics = new ConfigDiagnostics(eventBus, configManager);
265
+ const results = await diagnostics.runFullDiagnostics();
266
+ console.log(diagnostics.generateReport());
267
+ ```
268
+
269
+ ## 下一步
270
+
271
+ - 想直接拿一份“全功能可复制配置”:阅读 [配置模板(可复制)](./config-template.md)
272
+ - 想查当前已内置的类名规则:阅读 [规则参考](./rules-reference.md)
273
+ - 想先理解类名解析:阅读 [类名语法与生成规则](./concepts.md)
274
+ - 想把单位处理写稳:阅读 [单位与转换策略](./units.md)
275
+