2022-09-11 16:46:21 +08:00
|
|
|
/** 处理环境变量 */
|
2021-10-16 16:16:58 +08:00
|
|
|
const warpperEnv = (envConf: Recordable): ViteEnv => {
|
2022-09-11 16:46:21 +08:00
|
|
|
/** 此处为默认值,无需修改 */
|
2021-12-06 17:11:15 +08:00
|
|
|
const ret: ViteEnv = {
|
|
|
|
VITE_PORT: 8848,
|
|
|
|
VITE_PUBLIC_PATH: "",
|
|
|
|
VITE_PROXY_DOMAIN: "",
|
2021-12-14 10:51:07 +08:00
|
|
|
VITE_PROXY_DOMAIN_REAL: "",
|
2021-12-17 15:09:02 +08:00
|
|
|
VITE_ROUTER_HISTORY: "",
|
2022-10-26 19:51:06 +08:00
|
|
|
VITE_LEGACY: false,
|
2022-10-27 02:19:23 +08:00
|
|
|
VITE_CDN: false,
|
|
|
|
VITE_COMPRESSION: "none"
|
2021-12-06 17:11:15 +08:00
|
|
|
};
|
2021-10-16 16:16:58 +08:00
|
|
|
|
|
|
|
for (const envName of Object.keys(envConf)) {
|
|
|
|
let realName = envConf[envName].replace(/\\n/g, "\n");
|
|
|
|
realName =
|
|
|
|
realName === "true" ? true : realName === "false" ? false : realName;
|
|
|
|
|
|
|
|
if (envName === "VITE_PORT") {
|
|
|
|
realName = Number(realName);
|
|
|
|
}
|
|
|
|
ret[envName] = realName;
|
|
|
|
if (typeof realName === "string") {
|
|
|
|
process.env[envName] = realName;
|
|
|
|
} else if (typeof realName === "object") {
|
|
|
|
process.env[envName] = JSON.stringify(realName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
};
|
2021-12-06 17:11:15 +08:00
|
|
|
|
2022-09-11 16:46:21 +08:00
|
|
|
/** 跨域代理重写 */
|
2021-12-06 17:11:15 +08:00
|
|
|
const regExps = (value: string, reg: string): string => {
|
2022-08-22 21:34:55 +08:00
|
|
|
return value.replace(new RegExp(`^${reg}`, "g"), "");
|
2021-12-06 17:11:15 +08:00
|
|
|
};
|
|
|
|
|
2022-09-11 16:46:21 +08:00
|
|
|
/** 环境变量 */
|
2021-10-16 16:16:58 +08:00
|
|
|
const loadEnv = (): ViteEnv => {
|
|
|
|
return import.meta.env;
|
|
|
|
};
|
|
|
|
|
2021-12-06 17:11:15 +08:00
|
|
|
export { warpperEnv, regExps, loadEnv };
|