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.

79 lines
2.2 KiB

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