html css 微信小程序,tailwindcss 支持微信小程序配置

安装postcss插件

npm install -D postcss-class-rename

postcss-class-rename 是将小程序不支持的css类重命名

tailwindcss配置移除不支持的css样式

module.exports = {

// Tree-shake unused styles in production build

// purge: ['./src/**/*.{vue,js,ts,jsx,tsx,html}'],

purge: [],

darkMode: false, // or 'media' or 'class'

theme: {

extend: {},

// Disable breakpoints

screen: {}

},

variants: {

extend: {},

},

plugins: [],

corePlugins: {

space: false,

divideWidth: false,

divideColor: false,

divideStyle: false,

divideOpacity: false,

}

}

由于上面space/divideWidth等样式包含微信小程序不支持的写法:.className > :not([hidden]) ~ :not([hidden]),所以移除。

uniapp 配置postcss.config.js如下:

const path = require('path')

module.exports = {

parser: require('postcss-comment'),

plugins: [

require('postcss-import')({

resolve(id, basedir, importOptions) {

if (id.startsWith('~@/')) {

return path.resolve(process.env.UNI_INPUT_DIR, id.substr(3))

} else if (id.startsWith('@/')) {

return path.resolve(process.env.UNI_INPUT_DIR, id.substr(2))

} else if (id.startsWith('/') && !id.startsWith('//')) {

return path.resolve(process.env.UNI_INPUT_DIR, id.substr(1))

}

return id

}

}),

/* ******* 引入tailwindcss ******* */

require('tailwindcss')({}),

//

// // 根据平台差异进行不同的样式处理

...(

process.env.UNI_PLATFORM !== "h5"

? [

// 使用postcss-class-name 包将小程序不支持的类名写法转换为支持的类名,如:"hover:xxx"

require("postcss-class-rename")({

"\\\\:": "--",

// "\\\\/": "--",

"\\\\.": "--",

".:": "--"

})

]

: [

require("autoprefixer")({

remove: true,

}),

]

),

/* ******* ******* */

require('@dcloudio/vue-cli-plugin-uni/packages/postcss'),

...(process.env.NODE_ENV === "production" ? ['purgecss'] : []),

]

}

/* ******* ******* */之间是关键配置

标签:false,process,微信,require,程序,tailwindcss,path,postcss,id

来源: https://www.cnblogs.com/li1234yun/p/14257579.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值