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