跳到主要内容

🧩 文件匹配

定义于: packages/weapp-tailwindcss/src/types/user-defined-options/index.ts:13

本页收录 6 个配置项,来源于 UserDefinedOptions

配置一览

配置一览
配置项类型默认值说明
cssMatcher(name: string) => boolean匹配 *.wxss/acss/jxss/ttss/qss/css/tyss匹配需要处理的 wxss 等样式文件。
htmlMatcher(name: string) => boolean匹配 *.wxml/axml/jxml/ksml/ttml/qml/tyml/xhsml/swan匹配需要处理的 wxml 等模板文件。
inlineWxsbooleanfalse是否转义 wxml 中的内联 wxs
jsMatcher(name: string) => boolean匹配 *.js/*.mjs/*.cjs(排除 node_modules)匹配需要处理的编译后 js 文件。
mainCssChunkMatcher(name: string, appType?: AppType) => boolean按 appType 匹配 app.css/common/main.css 等匹配负责注入 Tailwind CSS 变量作用域的 CSS Bundle。
wxsMatcher(name: string) => boolean()=>false匹配各端的 wxs/sjs/.filter.js 文件。

详细说明

cssMatcher

可选 | 类型: (name: string) => boolean

定义于: packages/weapp-tailwindcss/src/types/user-defined-options/matcher.ts:15

匹配需要处理的 wxss 等样式文件。

默认值 / 说明 / 示例

备注

返回 true 的样式会进入 PostCSS 处理链路,通常仅需覆盖非常规后缀或自定义目录。

默认值

name => /.+\\.(?:wx|ac|jx|tt|q|c|ty)ss$/.test(name)

示例

import { UnifiedViteWeappTailwindcssPlugin as uvtw } from 'weapp-tailwindcss/vite'

uvtw({
cssMatcher: name => /\\.(?:wxss|acss|css)$/.test(name),
})

参数:name: string

返回:boolean

htmlMatcher

可选 | 类型: (name: string) => boolean

定义于: packages/weapp-tailwindcss/src/types/user-defined-options/matcher.ts:9

匹配需要处理的 wxml 等模板文件。

默认值 / 说明 / 示例

备注

返回 true 的文件会进入模板处理流程,建议与 tailwind.config.jscontent 范围保持一致。

默认值

name => /.+\\.(?:(?:wx|ax|jx|ks|tt|q|ty|xhs)ml|swan)$/.test(name)

示例

import { UnifiedViteWeappTailwindcssPlugin as uvtw } from 'weapp-tailwindcss/vite'

uvtw({
htmlMatcher: name => /\\.(?:wxml|axml)$/.test(name),
})

参数:name: string

返回:boolean

inlineWxs

可选 | 类型: boolean | 默认值: false

定义于: packages/weapp-tailwindcss/src/types/user-defined-options/matcher.ts:65

是否转义 wxml 中的内联 wxs

默认值 / 说明 / 示例

备注

使用前同样需要在 tailwind.config.js 中声明 wxs 格式。

默认值

false

示例

import { UnifiedViteWeappTailwindcssPlugin as uvtw } from 'weapp-tailwindcss/vite'

uvtw({
inlineWxs: true,
})
<!-- index.wxml -->
<wxs module="inline">
// 我是内联wxs
// 下方的类名会被转义
var className = "after:content-['我是className']"
module.exports = {
className: className
}
</wxs>
<wxs src="./index.wxs" module="outside"/>
<view><view class="{{inline.className}}"></view><view class="{{outside.className}}"></view></view>

jsMatcher

可选 | 类型: (name: string) => boolean

定义于: packages/weapp-tailwindcss/src/types/user-defined-options/matcher.ts:21

匹配需要处理的编译后 js 文件。

默认值 / 说明 / 示例

备注

返回 true 的脚本会执行 class 名称转译,建议保持对 node_modules 的排除。

默认值

name => !name.includes('node_modules') && /.+\\.[cm]?js?$/.test(name)

示例

import { UnifiedViteWeappTailwindcssPlugin as uvtw } from 'weapp-tailwindcss/vite'

uvtw({
jsMatcher: name => !name.includes('node_modules') && /\\.m?js$/.test(name),
})

参数:name: string

返回:boolean

mainCssChunkMatcher

可选 | 类型: (name: string, appType?: AppType) => boolean

定义于: packages/weapp-tailwindcss/src/types/user-defined-options/matcher.ts:29

匹配负责注入 Tailwind CSS 变量作用域的 CSS Bundle。

默认值 / 说明 / 示例

备注

在处理 ::before/::after 等不兼容选择器时,建议手动指定文件位置。

默认值

const MPX_STYLES_DIR_PATTERN = /(?:^|\\/)styles\\/.*\\.(?:wx|ac|jx|tt|q|c|ty)ss$/i

function normalizePath(value) {
return value.replace(/\\\\/g, '/')
}

function matcher(name, appType) {
if (!appType) {
return true
}
if (appType === 'uni-app') {
return name.startsWith('common/main') || name.startsWith('app')
}
if (appType === 'uni-app-vite') {
return name.startsWith('app') || name.startsWith('common/main')
}
if (appType === 'mpx') {
const normalized = normalizePath(name)
if (normalized.startsWith('app')) {
return true
}
return MPX_STYLES_DIR_PATTERN.test(normalized)
}
if (appType === 'taro' || appType === 'remax' || appType === 'native') {
return name.startsWith('app')
}
if (appType === 'rax') {
return name.startsWith('bundle')
}
if (appType === 'kbone') {
return /^(?:common\\/)?miniprogram-app/.test(name)
}
return true
}

示例

import { UnifiedViteWeappTailwindcssPlugin as uvtw } from 'weapp-tailwindcss/vite'

uvtw({
mainCssChunkMatcher: name => name.startsWith('app') || name.startsWith('common/main'),
})

参数:name: stringappType?: AppType

返回:boolean

wxsMatcher

可选 | 类型: (name: string) => boolean | 默认值: ()=>false

定义于: packages/weapp-tailwindcss/src/types/user-defined-options/matcher.ts:40

匹配各端的 wxs/sjs/.filter.js 文件。

默认值 / 说明 / 示例

备注

配置前请确保在 tailwind.config.jscontent 中包含对应格式。

若同时处理内联 wxs,请配合 inlineWxs 开启。

默认值

()=>false

示例

import { UnifiedViteWeappTailwindcssPlugin as uvtw } from 'weapp-tailwindcss/vite'

uvtw({
wxsMatcher: name => /\\.(?:wxs|sjs|filter\\.js)$/.test(name),
})

参数:name: string

返回:boolean