vite.config.js 928 B

123456789101112131415161718192021222324252627282930
  1. import { fileURLToPath, URL } from 'node:url'
  2. import { defineConfig, loadEnv } from 'vite'
  3. import vue from '@vitejs/plugin-vue'
  4. // qiankun 主应用:不需要 vite-plugin-qiankun(只有子应用需要),
  5. // 只需保证子应用资源允许跨域 + 提供挂载容器即可。
  6. export default defineConfig(({ mode }) => {
  7. const env = loadEnv(mode, process.cwd(), '')
  8. return {
  9. plugins: [vue()],
  10. resolve: {
  11. alias: {
  12. '@': fileURLToPath(new URL('./src', import.meta.url)),
  13. },
  14. },
  15. server: {
  16. host: '0.0.0.0',
  17. port: Number(env.VITE_PORT) || 8000,
  18. strictPort: true, // 端口被占时直接报错,避免静默降级导致子应用地址错乱
  19. // 开发环境将 /api 代理到后端,避免跨域
  20. proxy: {
  21. '/api': {
  22. target: env.VITE_PROXY_TARGET || 'http://localhost:8080',
  23. changeOrigin: true,
  24. },
  25. },
  26. },
  27. }
  28. })