From a4e70b9efe78ccf15c4e2d93ac194452f9a7a3e3 Mon Sep 17 00:00:00 2001 From: LittleSaya <2472609815@qq.com> Date: Thu, 13 Jul 2023 10:44:13 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=9A=E8=BF=87=E6=8A=8A=E5=90=8D=E7=A7=B0?= =?UTF-8?q?=E7=BC=96=E7=A0=81=E6=88=90hex=EF=BC=8C=E4=BD=BF=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E8=83=BD=E5=A4=9F=E5=9C=A8VITE=5FGLOB=5FAPP=5FTITLE?= =?UTF-8?q?=E5=8C=85=E5=90=AB=E7=89=B9=E6=AE=8A=E5=AD=97=E7=AC=A6=E6=97=B6?= =?UTF-8?q?=E6=AD=A3=E5=B8=B8=E6=89=93=E5=8C=85=20(#2910)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update env.ts 使getVariableName能处理含有特殊字符的标题 * Update appConfig.ts 是getVariableName能处理包含特殊字符的标题的情况 --- internal/vite-config/src/plugins/appConfig.ts | 11 ++++++++++- src/utils/env.ts | 13 ++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/internal/vite-config/src/plugins/appConfig.ts b/internal/vite-config/src/plugins/appConfig.ts index a4fb9542a..98594b1a0 100644 --- a/internal/vite-config/src/plugins/appConfig.ts +++ b/internal/vite-config/src/plugins/appConfig.ts @@ -74,7 +74,16 @@ async function createAppConfigPlugin({ * @param env */ const getVariableName = (title: string) => { - return `__PRODUCTION__${title || '__APP'}__CONF__`.toUpperCase().replace(/\s/g, ''); + function strToHex(str: string) { + const result: string[] = []; + for (let i = 0; i < str.length; ++i) { + const hex = str.charCodeAt(i).toString(16); + result.push(('000' + hex).slice(-4)); + } + return result.join('').toUpperCase(); + } + + return `__PRODUCTION__${strToHex(title) || '__APP'}__CONF__`.toUpperCase().replace(/\s/g, ''); }; async function getConfigSource(appTitle: string) { diff --git a/src/utils/env.ts b/src/utils/env.ts index 16af4f85a..ef0433cf5 100644 --- a/src/utils/env.ts +++ b/src/utils/env.ts @@ -2,9 +2,16 @@ import type { GlobEnvConfig } from '/#/config'; import pkg from '../../package.json'; const getVariableName = (title: string) => { - return `__PRODUCTION__${title.replace(/\s/g, '_').replace(/-/g, '_') || '__APP'}__CONF__` - .toUpperCase() - .replace(/\s/g, ''); + function strToHex(str: string) { + const result: string[] = []; + for (let i = 0; i < str.length; ++i) { + const hex = str.charCodeAt(i).toString(16); + result.push(('000' + hex).slice(-4)); + } + return result.join('').toUpperCase(); + } + + return `__PRODUCTION__${strToHex(title) || '__APP'}__CONF__`.toUpperCase().replace(/\s/g, ''); }; export function getCommonStoragePrefix() {