From 092bef3e26d4a5b49235fb9dccd50ad6807d10e4 Mon Sep 17 00:00:00 2001
From: zhangchen <1652267879@qq.com>
Date: 星期二, 16 九月 2025 17:31:54 +0800
Subject: [PATCH] 修改vite.config文件

---
 postcss.config.js |   49 +++++++++++++++++++++++++++++++++----------------
 1 files changed, 33 insertions(+), 16 deletions(-)

diff --git a/postcss.config.js b/postcss.config.js
index b493b9a..6ed0868 100644
--- a/postcss.config.js
+++ b/postcss.config.js
@@ -1,24 +1,41 @@
+// module.exports = {
+//   plugins: {
+//     'postcss-pxtorem': {
+//       rootValue: 37.5,
+//       propList: ['*'],
+//       include: file => {
+//         if (!file) return false;
+//         const normalized = file.replace(/\\/g, '/');
+//         // 只转换 mobile 目录里的样式 OR element-plus 目录里的样式
+//         // 但 element-plus 样式只在 mobile 目录被引用时才生效,需保证引用范围
+//         return normalized.includes('/src/views/mobile/') || normalized.includes('/node_modules/element-plus/');
+//       },
+//       exclude: file => {
+//         if (!file) return false;
+//         const normalized = file.replace(/\\/g, '/');
+//         // 排除除 element-plus 外的 node_modules,防止无关样式被转
+//         if (/node_modules/.test(normalized) && !normalized.includes('/node_modules/element-plus/')) {
+//           return true;
+//         }
+//         return false;
+//       },
+//       minPixelValue: 2,
+//     }
+//   }
+// }
+
 module.exports = {
   plugins: {
     'postcss-pxtorem': {
       rootValue: 37.5,
       propList: ['*'],
-      include: file => {
-        if (!file) return false;
-        const normalized = file.replace(/\\/g, '/');
-        // 只转换 mobile 目录里的样式 OR element-plus 目录里的样式
-        // 但 element-plus 样式只在 mobile 目录被引用时才生效,需保证引用范围
-        return normalized.includes('/src/views/mobile/') || normalized.includes('/node_modules/element-plus/');
-      },
-      exclude: file => {
-        if (!file) return false;
-        const normalized = file.replace(/\\/g, '/');
-        // 排除除 element-plus 外的 node_modules,防止无关样式被转
-        if (/node_modules/.test(normalized) && !normalized.includes('/node_modules/element-plus/')) {
-          return true;
-        }
-        return false;
-      },
+      // ✅ 用正则匹配路径,不依赖字符串 includes
+      include: [
+        /src[\/\\]views[\/\\]mobile/, // 只转 mobile 目录
+        // /node_modules[\/\\]element-plus/ // 转 element-plus 样式
+      ],
+      // ✅ 排除其他 node_modules
+      exclude: (file) => /node_modules/.test(file) && !/node_modules[\/\\]element-plus/.test(file),
       minPixelValue: 2,
     }
   }

--
Gitblit v1.8.0