forked from ttk-cli/uni-vue3-vite-ts-pinia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunocss.config.ts
51 lines (47 loc) · 1.21 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
import presetRemToPx from '@unocss/preset-rem-to-px'
import { defineConfig, Preset, presetAttributify, presetIcons, presetUno, Rule } from 'unocss'
// https://github.com/unocss/unocss
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` })]
})
}
export const createConfig = () => {
return defineConfig({
presets: [
presetUno(),
presetAttributify(),
presetIcons({
prefix: '',
extraProperties: {
display: 'inline-block',
cursor: 'pointer',
'font-size': '20px',
},
}),
presetRemToPx({
baseFontSize: 4,
}) as Preset,
],
include: [/\.vue$/, /pages.json$/],
rules: getSizeRules(sizeMapping),
})
}
export default createConfig()