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.

72 lines
1.8 KiB

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