vite.config.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { fileURLToPath, URL } from 'node:url'
  2. import { defineConfig, loadEnv } from 'vite'
  3. import vue from '@vitejs/plugin-vue'
  4. import vueDevTools from 'vite-plugin-vue-devtools'
  5. import Components from 'unplugin-vue-components/vite'
  6. import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'
  7. // https://vite.dev/config/
  8. export default defineConfig(({ mode }) => {
  9. // 加载环境变量
  10. const env = loadEnv(mode, process.cwd(), '')
  11. // 获取当前环境的API主机
  12. const apiHost = env.VITE_APP_HOST
  13. // 添加日志输出
  14. console.log(`🚀CurrentMode: ${mode}`)
  15. console.log(`🚀HostAPI: ${apiHost}`)
  16. console.log(`🚀ProxyAPI: ${apiHost}`)
  17. return {
  18. plugins: [
  19. vue(),
  20. vueDevTools(),
  21. Components({
  22. resolvers: [
  23. AntDesignVueResolver({
  24. importStyle: false, // css in js
  25. }),
  26. ],
  27. }),
  28. ],
  29. resolve: {
  30. alias: {
  31. '@': fileURLToPath(new URL('./src', import.meta.url)),
  32. },
  33. },
  34. server: {
  35. proxy: {
  36. '/portal-service-server': {
  37. target: apiHost,
  38. changeOrigin: true,
  39. secure: false,
  40. rewrite: (path) => path,
  41. },
  42. '/pub': {
  43. target: apiHost,
  44. changeOrigin: true,
  45. secure: false,
  46. rewrite: (path) => path,
  47. },
  48. },
  49. cors: true,
  50. },
  51. }
  52. })