vite-plugin-transform-wx-class
v0.0.2
Published
Downloads
5
Readme
vite-plugin-transform-wx-class
使用该插件转换微信小程序中带有特殊转义
class
,例如\[
\!
\.
,结合unocss 小程序预设,实现unocss
在小程序中开发使用
转换规则
const transformRules = {
'.': '-d-',
'/': '-s-',
':': '-c-',
'%': '-p-',
'!': '-e-',
'#': '-w-',
'(': '-bl-',
')': '-br-',
'[': '-fl-',
']': '-fr-',
'$': '-r-',
}
安装
pnpm add -D unocss vite-plugin-transform-wx-class unocss-preset-wxapp
vite.config.ts
import { defineConfig } from 'vite'
import uni from '@dcloudio/vite-plugin-uni'
import Unocss from 'unocss/vite'
import presetWxapp from 'unocss-preset-wxapp'
import transformWxClass, { transformSelector } from 'vite-plugin-transform-wx-class'
export default defineConfig({
plugins: [
uni(),
Unocss({
presets: [
presetWxapp(),
],
shortcuts: [
{
'border-base': 'border border-gray-500_10',
'center': 'flex justify-center items-center',
},
],
postprocess: (css) => {
css.selector = transformSelector(css.selector)
return css
},
}),
transformWxClass(),
],
})