Browse Source
通过把名称编码成hex,使项目能够在VITE_GLOB_APP_TITLE包含特殊字符时正常打包 (#2910)
* Update env.ts
使getVariableName能处理含有特殊字符的标题
* Update appConfig.ts
是getVariableName能处理包含特殊字符的标题的情况
pull/2917/head
LittleSaya
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
20 additions and
4 deletions
-
internal/vite-config/src/plugins/appConfig.ts
-
src/utils/env.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) { |
|
|
|
|
|
|
|
@ -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() { |
|
|
|
|