西藏巴青项目

vite.config.js 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { defineConfig, loadEnv } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import path from 'path'
  4. import { fileURLToPath } from 'url'
  5. const __dirname = path.dirname(fileURLToPath(import.meta.url))
  6. /** 与 ruoyi-ui vue.config.js publicPath 一致:生产 /screen,开发 / */
  7. function resolvePublicPath(mode, env) {
  8. if (mode !== 'production') {
  9. return '/'
  10. }
  11. const raw = String(env.VITE_APP_PUBLIC_PATH || '/screen').trim()
  12. if (!raw || raw === '/') {
  13. return '/'
  14. }
  15. return `/${raw.replace(/^\/+|\/+$/g, '')}/`
  16. }
  17. // https://vite.dev/config/
  18. export default defineConfig(({ mode }) => {
  19. const env = loadEnv(mode, process.cwd(), '')
  20. const base = resolvePublicPath(mode, env)
  21. const baseApi = env.VITE_APP_BASE_API || '/dev-api'
  22. const proxyTarget = (env.VITE_PROXY_TARGET || 'http://192.168.1.6:8010').replace(/\/$/, '')
  23. const proxy = {
  24. [baseApi]: {
  25. target: proxyTarget,
  26. changeOrigin: true,
  27. rewrite: (path) => path.replace(new RegExp(`^${baseApi}`), '')
  28. },
  29. '^/v3/api-docs/(.*)': {
  30. target: proxyTarget,
  31. changeOrigin: true
  32. }
  33. }
  34. const llmTarget = env.LLM_PROXY_TARGET
  35. if (llmTarget) {
  36. proxy['^/llm-dev-proxy'] = {
  37. target: llmTarget.replace(/\/$/, ''),
  38. changeOrigin: true,
  39. rewrite: (path) => path.replace(/^\/llm-dev-proxy/, '')
  40. }
  41. }
  42. return {
  43. base,
  44. plugins: [vue()],
  45. resolve: {
  46. alias: {
  47. '@': path.resolve(__dirname, 'src')
  48. }
  49. },
  50. server: {
  51. host: true,
  52. port: 5188,
  53. strictPort: false,
  54. proxy
  55. }
  56. }
  57. })