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.

31 lines
831 B

  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_HIDE_HOME: "false",
  10. VITE_COMPRESSION: "none"
  11. };
  12. for (const envName of Object.keys(envConf)) {
  13. let realName = envConf[envName].replace(/\\n/g, "\n");
  14. realName =
  15. realName === "true" ? true : realName === "false" ? false : realName;
  16. if (envName === "VITE_PORT") {
  17. realName = Number(realName);
  18. }
  19. ret[envName] = realName;
  20. if (typeof realName === "string") {
  21. process.env[envName] = realName;
  22. } else if (typeof realName === "object") {
  23. process.env[envName] = JSON.stringify(realName);
  24. }
  25. }
  26. return ret;
  27. };
  28. export { warpperEnv };