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.

75 lines
2.0 KiB

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