wireguard-dashboard-admin/build/index.ts

36 lines
900 B
TypeScript
Raw Normal View History

/** 处理环境变量 */
2021-10-16 16:16:58 +08:00
const warpperEnv = (envConf: Recordable): ViteEnv => {
2022-11-26 19:14:08 +08:00
/** 此处为默认值 */
2021-12-06 17:11:15 +08:00
const ret: ViteEnv = {
VITE_PORT: 8848,
VITE_PUBLIC_PATH: "",
2021-12-17 15:09:02 +08:00
VITE_ROUTER_HISTORY: "",
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-11-26 19:14:08 +08:00
/** 获取环境变量 */
2021-10-16 16:16:58 +08:00
const loadEnv = (): ViteEnv => {
return import.meta.env;
};
2022-11-10 12:28:10 +08:00
export { warpperEnv, loadEnv };