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.

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