From 53e89abfd8c576163d232ea7ca76e7dd0d085e39 Mon Sep 17 00:00:00 2001 From: coward Date: Wed, 21 Aug 2024 08:54:33 +0800 Subject: [PATCH] =?UTF-8?q?:art:=E8=B7=AF=E7=94=B1=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E6=94=B9=E4=B8=BAhash=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.development | 2 ++ .env.production | 4 +++- vite.config.js | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/.env.development b/.env.development index 9feaca6..aa4ea54 100644 --- a/.env.development +++ b/.env.development @@ -1,6 +1,8 @@ # 资源公共路径,需要以 /开头和结尾 VITE_PUBLIC_PATH = '/' +VITE_USE_HASH = true + # 是否启用MOCK VITE_USE_MOCK = true diff --git a/.env.production b/.env.production index 551b8b1..81b63c2 100644 --- a/.env.production +++ b/.env.production @@ -1,5 +1,7 @@ # 资源公共路径,需要以 /开头和结尾 -VITE_PUBLIC_PATH = '/' +VITE_PUBLIC_PATH = '/web' + +VITE_USE_HASH = true # 是否启用MOCK VITE_USE_MOCK = false diff --git a/vite.config.js b/vite.config.js index b3245cb..04c252f 100644 --- a/vite.config.js +++ b/vite.config.js @@ -4,6 +4,9 @@ import { convertEnv, getSrcPath, getRootPath } from './build/utils' import { createVitePlugins } from './build/plugin' import { OUTPUT_DIR, PROXY_CONFIG } from './build/constant' +const INVALID_CHAR_REGEX = /[\x00-\x1F\x7F<>*#"{}|^[\]`;?:&=+$,]/g; +const DRIVE_LETTER_REGEX = /^[a-z]:/i; + export default defineConfig(({ command, mode }) => { const srcPath = getSrcPath() const rootPath = getRootPath() @@ -38,6 +41,19 @@ export default defineConfig(({ command, mode }) => { outDir: OUTPUT_DIR || 'dist', reportCompressedSize: false, // 启用/禁用 gzip 压缩大小报告 chunkSizeWarningLimit: 1024, // chunk 大小警告的限制(单位kb) + rollupOptions: { + output: { + sanitizeFileName(name) { + const match = DRIVE_LETTER_REGEX.exec(name); + const driveLetter = match ? match[0] : ''; + // substr 是被淘汰語法,因此要改 slice + return ( + driveLetter + + name.slice(driveLetter.length).replace(INVALID_CHAR_REGEX, "") + ); + } + } + } }, } })