瀏覽代碼

清除缓存机制优化

liuhairui 1 年之前
父節點
當前提交
f721b230ed
共有 2 個文件被更改,包括 25 次插入8 次删除
  1. 7 1
      index.html
  2. 18 7
      vite.config.js

+ 7 - 1
index.html

@@ -6,8 +6,14 @@
     <meta http-equiv="X-UA-Compatible" content="IE=edge">
     <meta name="viewport" content="width=device-width,initial-scale=1.0">
     <meta content="vue-admin首页" name="keywords" />
+	
+	<!-- 自动更新清除缓存机制 -->
+		<meta http-equiv="pragma" content="no-cache">
+		<meta http-equiv="cache-control" content="no-cache, no-store, must-revalidate">
+		<meta http-equiv="expires" content="0">
+	
     <link rel="icon" href="favicon.ico">
-    <link rel="stylesheet" type="text/css" media="print" href="https://cdn.jsdelivr.net/npm/vue-plugin-hiprint@latest/dist/print-lock.css">
+    <link rel="stylesheet" type="text/css" media="print" href="/src/assets/css/print-lock.css">
     <title></title>
 </head>
 

+ 18 - 7
vite.config.js

@@ -43,13 +43,20 @@ export default ({
 
   const esbuild = {}
 
+  // const rollupOptions = {
+  //   output: {
+  //     entryFileNames: 'js/087AC4D233B64EB0[name].js',
+  //     chunkFileNames: 'js/087AC4D233B64EB0[name].js',
+  //     assetFileNames: 'assets/087AC4D233B64EB0[name].[ext]',
+  //   },
+  // }
   const rollupOptions = {
-    output: {
-      entryFileNames: 'js/087AC4D233B64EB0[name].js',
-      chunkFileNames: 'js/087AC4D233B64EB0[name].js',
-      assetFileNames: 'assets/087AC4D233B64EB0[name].[ext]',
-    },
-  }
+      output: {
+        entryFileNames: 'js/[name].[hash].js', // 添加哈希值
+        chunkFileNames: 'js/[name].[hash].js', // 添加哈希值
+        assetFileNames: 'assets/[name].[hash].[ext]', // 添加哈希值
+      },
+    }
 
   const config = {
     base: './', // index.html文件所在位置
@@ -71,7 +78,11 @@ export default ({
           target: `${process.env.VITE_BASE_PATH}:${process.env.VITE_SERVER_PORT}/`, // 代理到 目标路径
           changeOrigin: true,
           rewrite: path => path.replace(new RegExp('^' + process.env.VITE_BASE_API), ''),
-        }
+        },
+		[process.env.VITE_UPLOADS_API]: { // 需要代理的路径   例如 '/api'
+		  target: `${process.env.VITE_BASE_PATH}:${process.env.VITE_UPLOADS_PORT}/`, // 代理到 目标路径
+		  changeOrigin: true
+		},
       },
     },
     build: {