You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.0 KiB

  1. // 处理环境变量
  2. const warpperEnv = (envConf: Recordable): ViteEnv => {
  3. // 此处为默认值,无需修改
  4. const ret: ViteEnv = {
  5. VITE_PORT: 8848,
  6. VITE_PUBLIC_PATH: "",
  7. VITE_PROXY_DOMAIN: "",
  8. VITE_PROXY_DOMAIN_REAL: "",
  9. VITE_ROUTER_HISTORY: ""
  10. };
  11. for (const envName of Object.keys(envConf)) {
  12. let realName = envConf[envName].replace(/\\n/g, "\n");
  13. realName =
  14. realName === "true" ? true : realName === "false" ? false : realName;
  15. if (envName === "VITE_PORT") {
  16. realName = Number(realName);
  17. }
  18. ret[envName] = realName;
  19. if (typeof realName === "string") {
  20. process.env[envName] = realName;
  21. } else if (typeof realName === "object") {
  22. process.env[envName] = JSON.stringify(realName);
  23. }
  24. }
  25. return ret;
  26. };
  27. // 跨域代理重写
  28. const regExps = (value: string, reg: string): string => {
  29. return value.replace(new RegExp(reg, "g"), "");
  30. };
  31. // 环境变量
  32. const loadEnv = (): ViteEnv => {
  33. return import.meta.env;
  34. };
  35. export { warpperEnv, regExps, loadEnv };