@weapp-tailwindcss/runtime
v0.1.3
Published
Shared runtime helpers (transformers, clsx wrappers, metadata) for weapp-tailwindcss 在小程序运行时的适配层。
Maintainers
Readme
@weapp-tailwindcss/runtime
@weapp-tailwindcss/runtime 提供了一套在小程序环境中运行 Tailwind 相关工具时所需的“公共层”——包含统一的 escape/unescape 转换器、clsx 封装、weappTwIgnore、以及帮助将这些能力注入第三方库的 createRuntimeFactory。
- 📦 面向
tailwind-merge/tailwind-variants/cva等运行时库的公共依赖 - 🔁 自动共享 escape 映射,避免多处维护
- 🧩 暴露
weappTwIgnore(String.raw包装),供第三方消费
安装
pnpm add @weapp-tailwindcss/runtime快速上手
import { createRuntimeFactory } from '@weapp-tailwindcss/runtime'
import { createTailwindMerge, extendTailwindMerge, twJoin, twMerge } from 'tailwind-merge'
const create = createRuntimeFactory({
createTailwindMerge,
extendTailwindMerge,
twJoin,
twMerge,
})
const runtime = create()
runtime.twMerge('text-[#ececec]', 'text-[#ECECEC]') // => 自动 escape 的结果自定义 escape/unescape
import { createRuntimeFactory } from '@weapp-tailwindcss/runtime'
import { createTailwindMerge } from 'tailwind-merge'
const create = createRuntimeFactory({
createTailwindMerge,
extendTailwindMerge,
twJoin,
twMerge,
})
const custom = create({
escape: false, // 关闭最终 escape,适合 Web SSR
unescape: {
map: { '#': '__hash__' },
},
})其他导出
resolveTransformers:仅想复用 escape/unescape 时可以直接调用clsx/ClsxFn/ClassValue:再导出一次,避免子包重复安装clsxweappTwIgnore:模板字符串标签,是String.raw的别名,方便外部包跳过 weapp 转义
更多细节见官方文档:https://tw.icebreaker.top/docs/community/merge/runtime-api
