diff --git a/packages/vite-plugin/dist/index.js b/packages/vite-plugin/dist/index.js index 4812833..8187b99 100644 --- a/packages/vite-plugin/dist/index.js +++ b/packages/vite-plugin/dist/index.js @@ -2148,10 +2148,6 @@ if (typeof window !== 'undefined') { return; } let _node = node; - // 兼容 标签 - if (_node.startsWith("", ""); - } // uniappx 插件模式 if (!config.uniapp.isPlugin) { // 为 text 节点添加暗黑模式文本颜色 @@ -2192,7 +2188,10 @@ if (typeof window !== 'undefined') { const hasDynamicClass = _node.includes(":class="); // 如果没有动态类名,添加空的动态类名绑定 if (!hasDynamicClass) { - _node = _node.slice(0, -1) + ` :class="{}"` + ">"; + // 优化写法,避免重复字符串拼接 + const insertIndex = _node.length - (_node.endsWith("/>") ? 2 : 1); + _node = + _node.slice(0, insertIndex) + ` :class="{}"` + _node.slice(insertIndex); } // 获取暗黑模式类名 let darkClassNames = classNames.filter((name) => name.startsWith("dark-colon-")); diff --git a/packages/vite-plugin/package.json b/packages/vite-plugin/package.json index b928694..22a0744 100644 --- a/packages/vite-plugin/package.json +++ b/packages/vite-plugin/package.json @@ -1,6 +1,6 @@ { "name": "@cool-vue/vite-plugin", - "version": "8.2.12", + "version": "8.2.13", "description": "cool-admin、cool-uni builder", "types": "./dist/index.d.ts", "main": "/dist/index.js", diff --git a/packages/vite-plugin/src/uniapp-x/tailwind.ts b/packages/vite-plugin/src/uniapp-x/tailwind.ts index 89b03c3..44d7e04 100644 --- a/packages/vite-plugin/src/uniapp-x/tailwind.ts +++ b/packages/vite-plugin/src/uniapp-x/tailwind.ts @@ -282,11 +282,6 @@ function transformPlugin(): Plugin { let _node = node; - // 兼容 标签 - if (_node.startsWith("", ""); - } - // uniappx 插件模式 if (!config.uniapp.isPlugin) { // 为 text 节点添加暗黑模式文本颜色 @@ -332,7 +327,11 @@ function transformPlugin(): Plugin { // 如果没有动态类名,添加空的动态类名绑定 if (!hasDynamicClass) { - _node = _node.slice(0, -1) + ` :class="{}"` + ">"; + // 优化写法,避免重复字符串拼接 + const insertIndex = _node.length - (_node.endsWith("/>") ? 2 : 1); + + _node = + _node.slice(0, insertIndex) + ` :class="{}"` + _node.slice(insertIndex); } // 获取暗黑模式类名