tailwindcss 小程序版本预设
tailwindcss-preset for miniprogram
用 tailwindcss
来改善你的小程序开发体验吧
大部分有用的 tailwindcss utilities 兼容小程序 + rem 转 rpx (默认 1rem = 32rpx)
Installation
npm i -D tailwindcss-miniprogram-preset
# or
yarn add -D tailwindcss-miniprogram-preset
Then
Installing Tailwind CSS as a PostCSS plugin
and npx tailwindcss init
then add tailwindcss-miniprogram-preset
into your presets
:
// tailwind.config.js
module.exports = {
presets: [require('tailwindcss-miniprogram-preset')]
// ...
}
Then import tailwindcss
/* @tailwind base;
@tailwind components; */
@tailwind utilities;
or Using with Preprocessors
// uni-app App.vue 公共部分
// 小程序不需要 'base' 'components'
// @import 'tailwindcss/base';
// @import 'tailwindcss/components';
// 只需引入工具类
@import "tailwindcss/utilities";
建议配合 vscode 插件 Tailwind CSS IntelliSense 使用
可以根据配置自动生成智能提示,可有效提升开发体验
使用 uni-app
的朋友可以直接使用提供的模板
uni-app-vue3-tailwind-vscode-template
默认配置都可通过 preset merge 策略开启
darkMode
默认 false
theme.screens
默认 false
, 不需要 pc 那种自适应important
默认 true
, 需要用它去覆盖原生样式purge.enabled
默认 process.env.NODE_ENV === 'production'
,可通过 NODE_ENV
环境变量,避免打包出来的 wxss 过大的问题,开发环境默认关闭class
的 rename
见下表解决方案: 做 class rename 处理
form | to | sample |
---|---|---|
\/ |
-div- |
w-1/4 -> w-1-div-4 |
\. |
-dot- |
w-1.5 -> w-1-dot-5 |
解决方案:
:not
选择器的 corePlugins
*
选择器的 corePlugins
, 例如默认添加 '*, ::before, ::after'
的插件hover:
focus:
这些)mode: 'jit'
即时编译模式,因为 wxml
里写 w-[762px]
,[
和 ]
,会被默认转义为空格,导致即时编译无效。解决方案:
utilities
, 不导入 base
和 components
核心插件:
corePlugins
选项根据您是将其配置为对象还是数组而表现不同。
如果您把 corePlugins
配置为一个对象,那么它就会被跨配置合并。
如果您把 corePlugins
配置为一个数组,它就会取代您配置的预设所提供的任何 corePlugins
配置。
如果开发时,HMR 热更新不起作用,可以更改 purge
选项
也可以直接用自定义的 purge
选项, 覆盖当前 preset
// tailwind.config.js
const miniprogramPreset = require('tailwindcss-miniprogram-preset')
/** @type {import('@types/tailwindcss/tailwind-config').TailwindConfig} */
module.exports = {
purge: miniprogramPreset.purge.content,
presets: [miniprogramPreset]
}
插件 | 是否启用 |
---|---|
preflight | 否 |
container | 否 |
space | 否 |
divideWidth | 否 |
divideColor | 否 |
divideStyle | 否 |
divideOpacity | 否 |
accessibility | 否 |
appearance | 是 |
backgroundAttachment | 是 |
backgroundClip | 是 |
backgroundColor | 是 |
backgroundImage | 是 |
gradientColorStops | 是 |
backgroundOpacity | 是 |
backgroundPosition | 是 |
backgroundRepeat | 是 |
backgroundSize | 是 |
borderCollapse | 是 |
borderColor | 是 |
borderOpacity | 是 |
borderRadius | 是 |
borderStyle | 是 |
borderWidth | 是 |
boxSizing | 是 |
cursor | 是 |
display | 是 |
flexDirection | 是 |
flexWrap | 是 |
placeItems | 否 |
placeContent | 否 |
placeSelf | 否 |
alignItems | 是 |
alignContent | 是 |
alignSelf | 是 |
justifyItems | 是 |
justifyContent | 是 |
justifySelf | 是 |
flex | 是 |
flexGrow | 是 |
flexShrink | 是 |
order | 是 |
float | 是 |
clear | 是 |
fontFamily | 否 |
fontWeight | 是 |
height | 否 |
fontSize | 是 |
lineHeight | 是 |
listStylePosition | 是 |
listStyleType | 是 |
margin | 否 |
maxHeight | 否 |
maxWidth | 是 |
minHeight | 是 |
minWidth | 是 |
objectFit | 是 |
objectPosition | 是 |
opacity | 是 |
outline | 是 |
overflow | 是 |
overscrollBehavior | 是 |
padding | 否 |
placeholderColor | 是 |
placeholderOpacity | 是 |
pointerEvents | 是 |
position | 是 |
inset | 否 |
resize | 是 |
boxShadow | 否 |
ringWidth | 否 |
ringOffsetColor | 否 |
ringOffsetWidth | 否 |
ringColor | 否 |
ringOpacity | 否 |
fill | 否 |
stroke | 否 |
strokeWidth | 否 |
tableLayout | 是 |
textAlign | 是 |
textColor | 是 |
textOpacity | 是 |
textOverflow | 是 |
fontStyle | 是 |
textTransform | 是 |
textDecoration | 是 |
fontSmoothing | 是 |
fontVariantNumeric | 是 |
letterSpacing | 是 |
userSelect | 是 |
verticalAlign | 是 |
visibility | 是 |
whitespace | 是 |
wordBreak | 是 |
width | 否 |
zIndex | 是 |
gap | 否 |
gridAutoFlow | 否 |
gridTemplateColumns | 否 |
gridAutoColumns | 否 |
gridColumn | 否 |
gridColumnStart | 否 |
gridColumnEnd | 否 |
gridTemplateRows | 否 |
gridAutoRows | 否 |
gridRow | 否 |
gridRowStart | 否 |
gridRowEnd | 否 |
transform | 是 |
transformOrigin | 是 |
scale | 是 |
rotate | 是 |
translate | 否 |
skew | 是 |
transitionProperty | 是 |
transitionTimingFunction | 是 |
transitionDuration | 是 |
transitionDelay | 是 |
animation | 是 |
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。