更新文件
This commit is contained in:
@ -82,6 +82,63 @@ export default ({ command, mode }) => {
|
||||
},
|
||||
},
|
||||
UnoCSS(),
|
||||
// 修复微信小程序 WXSS 兼容性问题
|
||||
{
|
||||
name: 'fix-wxss-compatibility',
|
||||
enforce: 'post',
|
||||
transform(code, id) {
|
||||
if (UNI_PLATFORM === 'mp-weixin' && (id.endsWith('.wxss') || id.endsWith('.css'))) {
|
||||
// 将 rgb(r g b / alpha) 转换为 rgba(r, g, b, alpha)
|
||||
code = code.replace(/rgb\((\d+)\s+(\d+)\s+(\d+)\s*\/\s*([\d.]+)\)/g, 'rgba($1, $2, $3, $4)')
|
||||
// 移除 ::backdrop 伪元素及其内容(微信小程序不支持)
|
||||
code = code.replace(/::backdrop\s*\{[^}]*\}/g, '')
|
||||
// 移除行首空格,避免 WXSS 解析错误
|
||||
code = code.replace(/^\s+/gm, '')
|
||||
// 移除或修复可能导致问题的属性选择器(UnoCSS attributify 生成)
|
||||
// 这些选择器包含转义序列(如 \32, \33)可能导致 WXSS 解析错误
|
||||
code = code.replace(/\[\\?\d+[^\]]*_a_[^\]]*=""]\{[^}]*\}/g, '')
|
||||
code = code.replace(/\[[^\]]*_a_[^\]]*=""]\{[^}]*\}/g, '')
|
||||
// 移除包含转义序列的属性选择器(如 [\32 6_a_25=""])
|
||||
code = code.replace(/\[\\\d+[^\]]*\]\{[^}]*\}/g, '')
|
||||
// 修复 SVG 数据 URL 中的引号问题,转义单引号
|
||||
code = code.replace(/url\("data:image\/svg\+xml[^"]*"\)/g, (match) => {
|
||||
return match.replace(/'/g, "\\'")
|
||||
})
|
||||
return {
|
||||
code,
|
||||
map: null,
|
||||
}
|
||||
}
|
||||
},
|
||||
generateBundle(options, bundle) {
|
||||
if (UNI_PLATFORM === 'mp-weixin') {
|
||||
// 处理所有生成的 CSS 文件
|
||||
Object.keys(bundle).forEach((fileName) => {
|
||||
const file = bundle[fileName]
|
||||
if (file.type === 'asset' && (fileName.endsWith('.wxss') || fileName.endsWith('.css'))) {
|
||||
let css = file.source.toString()
|
||||
// 将 rgb(r g b / alpha) 转换为 rgba(r, g, b, alpha)
|
||||
css = css.replace(/rgb\((\d+)\s+(\d+)\s+(\d+)\s*\/\s*([\d.]+)\)/g, 'rgba($1, $2, $3, $4)')
|
||||
// 移除 ::backdrop 伪元素及其内容(微信小程序不支持)
|
||||
css = css.replace(/::backdrop\s*\{[^}]*\}/g, '')
|
||||
// 移除行首空格,避免 WXSS 解析错误
|
||||
css = css.replace(/^\s+/gm, '')
|
||||
// 移除或修复可能导致问题的属性选择器(UnoCSS attributify 生成)
|
||||
// 这些选择器包含转义序列(如 \32, \33)可能导致 WXSS 解析错误
|
||||
css = css.replace(/\[\\?\d+[^\]]*_a_[^\]]*=""]\{[^}]*\}/g, '')
|
||||
css = css.replace(/\[[^\]]*_a_[^\]]*=""]\{[^}]*\}/g, '')
|
||||
// 移除包含转义序列的属性选择器(如 [\32 6_a_25=""])
|
||||
css = css.replace(/\[\\\d+[^\]]*\]\{[^}]*\}/g, '')
|
||||
// 修复 SVG 数据 URL 中的引号问题,转义单引号
|
||||
css = css.replace(/url\("data:image\/svg\+xml[^"]*"\)/g, (match) => {
|
||||
return match.replace(/'/g, "\\'")
|
||||
})
|
||||
file.source = css
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
},
|
||||
AutoImport({
|
||||
imports: ['vue', 'uni-app'],
|
||||
dts: 'src/types/auto-import.d.ts',
|
||||
|
||||
Reference in New Issue
Block a user