通过把名称编码成hex,使项目能够在VITE_GLOB_APP_TITLE包含特殊字符时正常打包 (#2910)

* Update env.ts

使getVariableName能处理含有特殊字符的标题

* Update appConfig.ts

是getVariableName能处理包含特殊字符的标题的情况
This commit is contained in:
LittleSaya 2023-07-13 10:44:13 +08:00 committed by GitHub
parent 4e3e721650
commit a4e70b9efe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 4 deletions

View File

@ -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) {

View File

@ -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() {