From 67b10071c8fa0d0d52cdf92ebbbc97fbd594b1b3 Mon Sep 17 00:00:00 2001
From: chengxiangling <291105840@qq.com>
Date: 星期日, 11 五月 2025 13:33:19 +0800
Subject: [PATCH] 提交config配置打包时划分文件目录并且去掉所有console和debugger

---
 vite.config.js |   78 ++++++++++++++++-----------------------
 1 files changed, 32 insertions(+), 46 deletions(-)

diff --git a/vite.config.js b/vite.config.js
index 15f197e..5de2661 100644
--- a/vite.config.js
+++ b/vite.config.js
@@ -11,58 +11,44 @@
 // https://vitejs.dev/config/
 export default defineConfig(({ mode, command }) => {
   const env = loadEnv(mode, process.cwd());
-  const { VITE_APP_ENV, VITE_APP_BASE_API } = env;
-  console.log(VITE_APP_BASE_API, VITE_APP_ENV);
-  // 鏍规嵁鐜鍙橀噺鍔ㄦ�佽缃唬鐞�
-  // const proxyConfig = () => {
-  //   const personProxy = {
-  //     "/prod-api": {
-  //       target: "http://192.168.50.160:8080",//"http://192.168.50.13:8080", // 寮�鍙戠幆澧冪殑鍚庣鍦板潃
-  //       changeOrigin: true,
-  //       rewrite: (path) => path.replace(/^\/prod-api/, ""),
-  //     },
-  //   };
-  //   const devProxy = {
-  //     "/prod-api": {
-  //       target: "http://192.168.50.160:8080", // 寮�鍙戠幆澧冪殑鍚庣鍦板潃
-  //       changeOrigin: true,
-  //       rewrite: (path) => path.replace(/^\/prod-api/, ""),
-  //     },
-  //   };
-
-  //   const testProxy = {
-  //     "/prod-api": {
-  //       target: "http://192.168.50.160:8080", // 娴嬭瘯鐜鐨勫悗绔湴鍧�
-  //       changeOrigin: true,
-  //       rewrite: (path) => path.replace(/^\/prod-api/, ""),
-  //     },
-  //   };
-
-  //   const prodProxy = {
-  //     "/prod-api": {
-  //       target: "http://192.168.50.160:8080", // 娴嬭瘯鐜鐨勫悗绔湴鍧�
-  //       changeOrigin: true,
-  //       rewrite: (path) => path.replace(/^\/prod-api/, ""),
-  //     },
-  //   };
-
-  //   switch (VITE_APP_ENV) {
-  //     case "development":
-  //       return personProxy;
-  //     case "int":
-  //       return devProxy;
-  //     case "uat":
-  //       return testProxy;
-  //     default: // 榛樿寮�鍙戠幆澧�
-  //       return prodProxy;
-  //   }
-  // };
+  const { VITE_APP_ENV } = env;
   return {
     // 閮ㄧ讲鐢熶骇鐜鍜屽紑鍙戠幆澧冧笅鐨刄RL銆�
     // 榛樿鎯呭喌涓嬶紝vite 浼氬亣璁句綘鐨勫簲鐢ㄦ槸琚儴缃插湪涓�涓煙鍚嶇殑鏍硅矾寰勪笂
     // 渚嬪 https://www.ruoyi.vip/銆傚鏋滃簲鐢ㄨ閮ㄧ讲鍦ㄤ竴涓瓙璺緞涓婏紝浣犲氨闇�瑕佺敤杩欎釜閫夐」鎸囧畾杩欎釜瀛愯矾寰勩�備緥濡傦紝濡傛灉浣犵殑搴旂敤琚儴缃插湪 https://www.ruoyi.vip/admin/锛屽垯璁剧疆 baseUrl 涓� /admin/銆�
     base: VITE_APP_ENV === "production" ? "/" : "/",
     plugins: createVitePlugins(env, command === "build"),
+    build: {
+      minify: "terser", // 蹇呴』寮�鍚細浣跨敤terserOptions鎵嶆湁鏁堟灉
+      terserOptions: {
+        compress: {
+          //鐢熶骇鐜鏃剁Щ闄onsole
+          drop_console: true,
+          drop_debugger: true,
+        },
+      },
+      rollupOptions: {
+        output: {
+          entryFileNames: "build/js/[name].[hash:6].js",
+          chunkFileNames: "build/js/vendor/[name].[hash:8].js",
+          manualChunks(id) {
+            console.log("馃殌 ~ manualChunks ~ id:", id);
+            if (id.includes("node_modules")) {
+              return "vendor";
+            }
+          },
+          assetFileNames: (assetInfo) => {
+            if (assetInfo.name.endsWith(".css")) {
+              return "build/css/[name].[hash][extname]";
+            }
+            if (/\.(png|jpe?g|gif|svg|webp|ico)$/.test(assetInfo.name)) {
+              return "build/img/[name].[hash][extname]";
+            }
+            return "build/assets/[name].[hash][extname]";
+          },
+        },
+      },
+    },
     resolve: {
       // https://cn.vitejs.dev/config/#resolve-alias
       alias: {

--
Gitblit v1.9.3