From 20c244cd5f559ce2d0515217a4529a961acf2334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E7=BB=A7=E9=A3=8E?= <1914007838@qq.com> Date: Mon, 24 Jun 2024 17:29:09 +0800 Subject: [PATCH 1/3] =?UTF-8?q?[feat]=E5=A2=9E=E5=8A=A0=E6=9E=84=E5=BB=BA?= =?UTF-8?q?=E6=97=B6=E7=89=88=E6=9C=AC=E6=96=87=E4=BB=B6=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/vite.config.ts | 114 ++++++++++++++++++++++++--------------------- 1 file changed, 62 insertions(+), 52 deletions(-) diff --git a/web/vite.config.ts b/web/vite.config.ts index c86cfc48af..730e07dc2d 100644 --- a/web/vite.config.ts +++ b/web/vite.config.ts @@ -3,66 +3,76 @@ import { resolve } from 'path'; import { defineConfig, loadEnv, ConfigEnv } from 'vite'; import vueSetupExtend from 'vite-plugin-vue-setup-extend'; import vueJsx from '@vitejs/plugin-vue-jsx' +import fs from 'fs'; + +const __VERSION__ = process.env.npm_package_version const pathResolve = (dir: string) => { - return resolve(__dirname, '.', dir); + return resolve(__dirname, '.', dir); }; const alias: Record = { - '/@': pathResolve('./src/'), - '@views': pathResolve('./src/views'), - 'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js', - '@dvaformflow':pathResolve('./src/viwes/plugins/dvaadmin_form_flow/src/') + '/@': pathResolve('./src/'), + '@views': pathResolve('./src/views'), + 'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js', + '@dvaformflow': pathResolve('./src/viwes/plugins/dvaadmin_form_flow/src/') }; const viteConfig = defineConfig((mode: ConfigEnv) => { - const env = loadEnv(mode.mode, process.cwd()); - return { - plugins: [vue(), vueJsx(), vueSetupExtend()], - root: process.cwd(), - resolve: { alias }, - base: mode.command === 'serve' ? './' : env.VITE_PUBLIC_PATH, - optimizeDeps: { - include: ['element-plus/es/locale/lang/zh-cn', 'element-plus/es/locale/lang/en', 'element-plus/es/locale/lang/zh-tw'], - }, - server: { - host: '0.0.0.0', - port: env.VITE_PORT as unknown as number, - open: true, - hmr: true, - proxy: { - '/gitee': { - target: 'https://gitee.com', - ws: true, - changeOrigin: true, - rewrite: (path) => path.replace(/^\/gitee/, ''), - }, - }, - }, - build: { - outDir: env.VITE_DIST_PATH || 'dist', - chunkSizeWarningLimit: 1500, - rollupOptions: { - output: { - entryFileNames: `assets/[name].[hash].js`, - chunkFileNames: `assets/[name].[hash].js`, - assetFileNames: `assets/[name].[hash].[ext]`, - compact: true, - manualChunks: { - vue: ['vue', 'vue-router', 'pinia'], - echarts: ['echarts'], - }, - }, - }, - }, - css: { preprocessorOptions: { css: { charset: false } } }, - define: { - __VUE_I18N_LEGACY_API__: JSON.stringify(false), - __VUE_I18N_FULL_INSTALL__: JSON.stringify(false), - __INTLIFY_PROD_DEVTOOLS__: JSON.stringify(false), - __VERSION__: JSON.stringify(process.env.npm_package_version), - }, - }; + const env = loadEnv(mode.mode, process.cwd()); + // 当Vite构建时,生成版本文件 + const generateVersionFile = () => { + const date = new Date(); + const version = `${__VERSION__}.${date.getFullYear()}${(date.getMonth() + 1).toString().padStart(2, '0')}${date.getDate().toString().padStart(2, '0')}`; + fs.writeFileSync('public/version.txt', version); + }; + generateVersionFile() + return { + plugins: [vue(), vueJsx(), vueSetupExtend()], + root: process.cwd(), + resolve: {alias}, + base: mode.command === 'serve' ? './' : env.VITE_PUBLIC_PATH, + optimizeDeps: { + include: ['element-plus/es/locale/lang/zh-cn', 'element-plus/es/locale/lang/en', 'element-plus/es/locale/lang/zh-tw'], + }, + server: { + host: '0.0.0.0', + port: env.VITE_PORT as unknown as number, + open: true, + hmr: true, + proxy: { + '/gitee': { + target: 'https://gitee.com', + ws: true, + changeOrigin: true, + rewrite: (path) => path.replace(/^\/gitee/, ''), + }, + }, + }, + build: { + outDir: env.VITE_DIST_PATH || 'dist', + chunkSizeWarningLimit: 1500, + rollupOptions: { + output: { + entryFileNames: `assets/[name].[hash].js`, + chunkFileNames: `assets/[name].[hash].js`, + assetFileNames: `assets/[name].[hash].[ext]`, + compact: true, + manualChunks: { + vue: ['vue', 'vue-router', 'pinia'], + echarts: ['echarts'], + }, + }, + }, + }, + css: {preprocessorOptions: {css: {charset: false}}}, + define: { + __VUE_I18N_LEGACY_API__: JSON.stringify(false), + __VUE_I18N_FULL_INSTALL__: JSON.stringify(false), + __INTLIFY_PROD_DEVTOOLS__: JSON.stringify(false), + __VERSION__: JSON.stringify(process.env.npm_package_version), + }, + }; }); export default viteConfig; -- Gitee From f88d982f00bb24416394e04535f8d922a8a6f8ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E7=BB=A7=E9=A3=8E?= <1914007838@qq.com> Date: Tue, 25 Jun 2024 10:00:16 +0800 Subject: [PATCH 2/3] =?UTF-8?q?[feat]=E5=A2=9E=E5=8A=A0nginx=E4=B8=8D?= =?UTF-8?q?=E7=BC=93=E5=AD=98index.html=20=E5=92=8Cindex.htm=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=EF=BC=8C=E6=90=AD=E9=85=8D=E5=89=8D=E7=AB=AF=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E8=87=AA=E5=8A=A8=E6=A3=80=E6=B5=8B=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker_env/nginx/my-80.conf | 4 ++++ docker_env/nginx/my.conf | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/docker_env/nginx/my-80.conf b/docker_env/nginx/my-80.conf index e50bdc4697..98d33bd98b 100644 --- a/docker_env/nginx/my-80.conf +++ b/docker_env/nginx/my-80.conf @@ -7,6 +7,10 @@ server { index index.html index.htm; root /usr/share/nginx/html; try_files $uri $uri/ /index.html; + # 禁止缓存html文件,避免前端页面不及时更新,需要用户手动刷新的情况 + if ($request_uri ~* "^/$|^/index.html|^/index.htm") { + add_header Cache-Control "no-store"; + } } location ~ ^/api/ { diff --git a/docker_env/nginx/my.conf b/docker_env/nginx/my.conf index 178d9793e1..dd6b3337a1 100644 --- a/docker_env/nginx/my.conf +++ b/docker_env/nginx/my.conf @@ -11,6 +11,10 @@ server { real_ip_header X-Forwarded-For; root /usr/share/nginx/html; index index.html index.php index.htm; + # 禁止缓存html文件,避免前端页面不及时更新,需要用户手动刷新的情况 + if ($request_uri ~* "^/$|^/index.html|^/index.htm") { + add_header Cache-Control "no-store"; + } } location /api/ { -- Gitee From 548cbac442f7a67514384e4fa9b8ac018a11766c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E7=BB=A7=E9=A3=8E?= <1914007838@qq.com> Date: Tue, 25 Jun 2024 10:01:32 +0800 Subject: [PATCH 3/3] =?UTF-8?q?[feat]=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=89=8D=E7=AB=AF=E4=BB=A3=E7=A0=81=E5=86=99=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/.gitignore | 3 ++- web/src/utils/upgrade.ts | 13 +++++++------ web/vite.config.ts | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/web/.gitignore b/web/.gitignore index 455b613680..8cef918682 100644 --- a/web/.gitignore +++ b/web/.gitignore @@ -21,4 +21,5 @@ pnpm-debug.log* *.njsproj *.sln *.sw? -public/version +# 构建版本文件,无需上传git +public/version-build diff --git a/web/src/utils/upgrade.ts b/web/src/utils/upgrade.ts index 6ca9e67968..a571863db8 100644 --- a/web/src/utils/upgrade.ts +++ b/web/src/utils/upgrade.ts @@ -5,8 +5,9 @@ import {ElNotification} from "element-plus"; import fs from "fs"; // 是否显示升级提示信息框 -export const IS_SHOW_UPGRADE_SESSION_KEY = 'isShowUpgrade'; -const versionKey = 'DVADMIN3_VERSION' +const IS_SHOW_UPGRADE_SESSION_KEY = 'isShowUpgrade'; +const VERSION_KEY = 'DVADMIN3_VERSION' +const VERSION_FILE_NAME = 'version-build' export function showUpgrade () { const isShowUpgrade = Session.get(IS_SHOW_UPGRADE_SESSION_KEY) ?? false @@ -28,13 +29,13 @@ export async function checkVersion(){ return } // 获取线上版本号 t为时间戳,防止缓存 - await axios.get(`/version?t=${new Date().getTime()}`).then(res => { + await axios.get(`/${VERSION_FILE_NAME}?t=${new Date().getTime()}`).then(res => { const {status, data} = res || {} if (status === 200) { // 获取当前版本号 - const localVersion = Local.get(versionKey) + const localVersion = Local.get(VERSION_KEY) // 将当前版本号持久缓存至本地 - Local.set(versionKey, data) + Local.set(VERSION_KEY, data) // 当用户本地存在版本号并且和线上版本号不一致时,进行页面刷新操作 if (localVersion && localVersion !== data) { // 本地缓存版本号和线上版本号不一致,弹出升级提示框 @@ -50,5 +51,5 @@ export async function checkVersion(){ export function generateVersionFile (){ // 生成版本文件到public目录下version文件中 const version = `${process.env.npm_package_version}.${new Date().getTime()}`; - fs.writeFileSync('public/version', version); + fs.writeFileSync(`public/${VERSION_FILE_NAME}`, version); } diff --git a/web/vite.config.ts b/web/vite.config.ts index d91057f5f7..ed6dec257e 100644 --- a/web/vite.config.ts +++ b/web/vite.config.ts @@ -3,7 +3,7 @@ import { resolve } from 'path'; import { defineConfig, loadEnv, ConfigEnv } from 'vite'; import vueSetupExtend from 'vite-plugin-vue-setup-extend'; import vueJsx from '@vitejs/plugin-vue-jsx' -import { generateVersionFile } from "./src/utils/upgrade"; +import { generateVersionFile } from "/@/utils/upgrade"; const pathResolve = (dir: string) => { return resolve(__dirname, '.', dir); -- Gitee