index.ts 856 B

1234567891011121314151617181920212223242526272829303132
  1. /** 处理环境变量 */
  2. const warpperEnv = (envConf: Recordable): ViteEnv => {
  3. /** 此处为默认值 */
  4. const ret: ViteEnv = {
  5. VITE_PORT: 8848,
  6. VITE_PUBLIC_PATH: "",
  7. VITE_ROUTER_HISTORY: "",
  8. VITE_CDN: false,
  9. VITE_API_SERVER: "",
  10. VITE_HIDE_HOME: "false",
  11. VITE_COMPRESSION: "none"
  12. };
  13. for (const envName of Object.keys(envConf)) {
  14. let realName = envConf[envName].replace(/\\n/g, "\n");
  15. realName =
  16. realName === "true" ? true : realName === "false" ? false : realName;
  17. if (envName === "VITE_PORT") {
  18. realName = Number(realName);
  19. }
  20. ret[envName] = realName;
  21. if (typeof realName === "string") {
  22. process.env[envName] = realName;
  23. } else if (typeof realName === "object") {
  24. process.env[envName] = JSON.stringify(realName);
  25. }
  26. }
  27. return ret;
  28. };
  29. export { warpperEnv };