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.

39 lines
1019 B

  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. };
  10. for (const envName of Object.keys(envConf)) {
  11. let realName = envConf[envName].replace(/\\n/g, "\n");
  12. realName =
  13. realName === "true" ? true : realName === "false" ? false : realName;
  14. if (envName === "VITE_PORT") {
  15. realName = Number(realName);
  16. }
  17. ret[envName] = realName;
  18. if (typeof realName === "string") {
  19. process.env[envName] = realName;
  20. } else if (typeof realName === "object") {
  21. process.env[envName] = JSON.stringify(realName);
  22. }
  23. }
  24. return ret;
  25. };
  26. // 跨域代理重写
  27. const regExps = (value: string, reg: string): string => {
  28. return value.replace(new RegExp(reg, "g"), "");
  29. };
  30. // 环境变量
  31. const loadEnv = (): ViteEnv => {
  32. return import.meta.env;
  33. };
  34. export { warpperEnv, regExps, loadEnv };