bg-[url('/images/homebg.png')] 这样的写法无法生效。请改用以下任一方式:
- 使用线上可访问的远程图片地址,例如 `bg-[url('https://example.com/bg.png')]`
- 将资源转成 `base64` 后内联到 `background-image`
- 改用 `cva 与 tailwind-variants 支持 章节。
### 多端项目:按需控制转义
`create` 工厂允许你为不同运行时定制 escape 策略:
```ts
const { twMerge: mergeForMiniProgram } = create()
const { twMerge: mergeForWeb } = create({
escape: false,
unescape: false,
})
mergeForMiniProgram('text-[#ececec]', 'text-[#ECECEC]') // → 'text-_b_hECECEC_B'
mergeForWeb('text-[#ececec]', 'text-[#ECECEC]') // → 'text-[#ECECEC]'
```
- `escape: false` 表示结果保持原样(适合 Web 或同构渲染)。
- `unescape: false` 可跳过运行前的「反转义」,用于确保输入不会被改写。
- 如果只想自定义映射表,传入 `escape: { map: { '#': '__hash__' } }` 即可;运行时会把自定义映射与默认映射合并,保证编译期和运行时的行为一致。
### 在线体验
```jsx live
function () {
return
{`const button = cva('inline-flex items-center px-4 py-2', {
variants: { intent: { primary: 'bg-primary text-primary-foreground', ghost: 'hover:bg-accent' } },
compoundVariants: [{ intent: 'primary', size: 'lg', class: 'shadow-lg' }],
})`}
)
}
```
buttonVariants({ intent: 'primary', size: 'lg' })