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.

78 lines
2.1 KiB

7 months ago
7 months ago
7 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
7 months ago
3 months ago
3 months ago
  1. import { defineConfig, loadEnv } from "vite";
  2. import react from "@vitejs/plugin-react";
  3. import { viteMockServe } from "vite-plugin-mock";
  4. import jotaiDebugLabel from "jotai/babel/plugin-debug-label";
  5. import jotaiReactRefresh from "jotai/babel/plugin-react-refresh";
  6. //import { TanStackRouterVite } from '@tanstack/router-vite-plugin'
  7. export const downLoadUrl = "http://127.0.0.1:8000";
  8. const proxyMap = {
  9. "/api/v1/package": "http://154.88.7.8:45321",
  10. "/api/v1/movie": "http://47.113.117.106:10000",
  11. //'/api/v1/certold': 'http://192.168.31.41:8000',
  12. "/api/v1/cert": "http://127.0.0.1:8000",
  13. //'/api/v1/cert': 'http://192.168.31.41:8000',
  14. "/api/v1/sys": "http://192.168.31.41:8686/",
  15. } as Record<any, string>;
  16. const proxyConfig = Object.keys(proxyMap).reduce(
  17. (acc, key) => {
  18. acc[key] = {
  19. target: proxyMap[key],
  20. changeOrigin: true,
  21. rewrite: (path: string) => path,
  22. };
  23. return acc;
  24. },
  25. {} as Record<any, any>,
  26. );
  27. // https://vitejs.dev/config/
  28. export default defineConfig(({ mode }) => {
  29. // 根据当前工作目录中的 `mode` 加载 .env 文件
  30. // 设置第三个参数为 '' 来加载所有环境变量,而不管是否有 `VITE_` 前缀。
  31. // @ts-ignore fix process
  32. const env = loadEnv(mode, process.cwd(), "");
  33. // 你可以在这里打印出 env 变量来检查加载的内容
  34. return {
  35. //定义别名的路径
  36. resolve: {
  37. alias: {
  38. "@": "/src",
  39. },
  40. },
  41. server: {
  42. cors: {
  43. origin: "*",
  44. },
  45. proxy: {
  46. ...proxyConfig,
  47. "/api": {
  48. target: env.API_URL,
  49. changeOrigin: true,
  50. rewrite: (path) => {
  51. return path;
  52. },
  53. },
  54. },
  55. },
  56. plugins: [
  57. react({
  58. babel: {
  59. presets: ["jotai/babel/preset"],
  60. plugins: [jotaiDebugLabel, jotaiReactRefresh],
  61. },
  62. }),
  63. viteMockServe({
  64. // 是否启用 mock 功能(默认值:process.env.NODE_ENV !== 'production')
  65. enable: false,
  66. // mock 文件的根路径,默认值:'mocks'
  67. mockPath: "mock",
  68. logger: true,
  69. }),
  70. //TanStackRouterVite(),
  71. ],
  72. };
  73. });