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.

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