2022-09-11 16:46:01 +08:00
|
|
|
/** 处理环境变量 */
|
2021-09-28 09:24:19 +08:00
|
|
|
const warpperEnv = (envConf: Recordable): ViteEnv => {
|
2022-11-17 18:12:03 +08:00
|
|
|
/** 此处为默认值 */
|
2021-12-04 01:16:50 +08:00
|
|
|
const ret: ViteEnv = {
|
|
|
|
VITE_PORT: 8848,
|
|
|
|
VITE_PUBLIC_PATH: "",
|
2021-12-15 13:25:18 +08:00
|
|
|
VITE_ROUTER_HISTORY: "",
|
2022-10-27 02:35:56 +08:00
|
|
|
VITE_CDN: false,
|
2023-05-05 22:55:12 +08:00
|
|
|
VITE_HIDE_HOME: "false",
|
2022-10-27 02:35:56 +08:00
|
|
|
VITE_COMPRESSION: "none"
|
2021-12-04 01:16:50 +08:00
|
|
|
};
|
2021-09-28 09:24:19 +08:00
|
|
|
|
|
|
|
for (const envName of Object.keys(envConf)) {
|
|
|
|
let realName = envConf[envName].replace(/\\n/g, "\n");
|
2021-07-20 17:16:42 +08:00
|
|
|
realName =
|
|
|
|
realName === "true" ? true : realName === "false" ? false : realName;
|
2021-09-28 09:24:19 +08:00
|
|
|
|
2021-07-20 17:16:42 +08:00
|
|
|
if (envName === "VITE_PORT") {
|
2021-03-01 15:26:05 +08:00
|
|
|
realName = Number(realName);
|
|
|
|
}
|
|
|
|
ret[envName] = realName;
|
2021-09-28 09:24:19 +08:00
|
|
|
if (typeof realName === "string") {
|
|
|
|
process.env[envName] = realName;
|
|
|
|
} else if (typeof realName === "object") {
|
|
|
|
process.env[envName] = JSON.stringify(realName);
|
|
|
|
}
|
2021-03-01 15:26:05 +08:00
|
|
|
}
|
|
|
|
return ret;
|
2021-09-28 09:24:19 +08:00
|
|
|
};
|
2021-12-04 01:16:50 +08:00
|
|
|
|
2022-12-19 11:58:49 +08:00
|
|
|
export { warpperEnv };
|