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.

74 lines
2.0 KiB

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