vue-pure-admin2/build/index.ts

42 lines
1.0 KiB
TypeScript
Raw Normal View History

2021-12-04 01:16:50 +08:00
// 处理环境变量
const warpperEnv = (envConf: Recordable): ViteEnv => {
2021-12-04 01:16:50 +08:00
// 此处为默认值,无需修改
const ret: ViteEnv = {
VITE_PORT: 8848,
VITE_PUBLIC_PATH: "",
VITE_PROXY_DOMAIN: "",
2021-12-13 17:39:13 +08:00
VITE_PROXY_DOMAIN_REAL: "",
VITE_ROUTER_HISTORY: "",
VITE_LEGACY: false
2021-12-04 01:16:50 +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-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;
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-12-04 01:16:50 +08:00
// 跨域代理重写
const regExps = (value: string, reg: string): string => {
return value.replace(new RegExp(reg, "g"), "");
};
// 环境变量
const loadEnv = (): ViteEnv => {
return import.meta.env;
};
2021-12-04 01:16:50 +08:00
export { warpperEnv, regExps, loadEnv };