-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathunocss.config.ts
75 lines (68 loc) · 2.08 KB
/
unocss.config.ts
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// https://github.com/unocss/unocss
import { defineConfig, Preset, presetAttributify, presetIcons, presetUno, Rule } from 'unocss'
import presetWeapp from 'unocss-preset-weapp'
import { transformerAttributify, transformerClass } from 'unocss-preset-weapp/transformer'
import presetRemToRpx from './preset-rem-to-rpx'
const sizeMapping: Record<string, string> = {
h: 'height',
w: 'width',
m: 'margin',
p: 'padding',
mt: 'margin-top',
mr: 'margin-right',
mb: 'margin-bottom',
ml: 'margin-left',
pt: 'padding-top',
pr: 'padding-right',
pb: 'padding-bottom',
pl: 'padding-left',
fs: 'font-size',
br: 'border-radius'
}
function getSizeRules(Mapping: Record<string, string>): Rule<{}>[] {
return Object.keys(Mapping).map(key => {
const value = Mapping[key]
return [new RegExp(`^${key}(\\d+)$`), ([, d]) => ({ [value]: `${d}rpx` })]
})
}
const customRules: Rule<{}>[] = [['fontColor-red', { color: 'red' }]]
const shortcuts = {
'custom-shortcut': 'text-lg text-orange hover:text-teal'
}
export const createConfig = () => {
return defineConfig({
rules: [...getSizeRules(sizeMapping), ...customRules],
shortcuts,
presets: [
presetUno(),
presetWeapp() as Preset,
presetAttributify(),
presetIcons({
prefix: 'icon-',
extraProperties: {
display: 'inline-block',
cursor: 'pointer',
'font-size': '32rpx'
},
collections: {
ep: () => import('@iconify-json/ep/icons.json').then(i => i.default)
}
}),
presetRemToRpx({
baseFontSize: 4
}) as Preset
],
// transformers: [
// // https://github.com/MellowCo/unocss-preset-weapp/tree/main/src/transformer/transformerAttributify
// transformerAttributify(),
// // https://github.com/MellowCo/unocss-preset-weapp/tree/main/src/transformer/transformerClass
// transformerClass()
// ],
theme: {
// 解决小程序不支持 * 选择器
preflightRoot: ['page,::before,::after']
},
include: [/\.vue$/, /pages.json$/]
})
}
export default createConfig()