Files
urbanLifeline/urbanLifelineWeb/packages/workcase/vite.config.ts

92 lines
2.0 KiB
TypeScript
Raw Normal View History

2025-12-06 14:49:46 +08:00
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
2025-12-13 14:13:31 +08:00
import { federation } from '@module-federation/vite'
2025-12-06 14:49:46 +08:00
import { resolve, dirname } from 'path'
import { fileURLToPath } from 'url'
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
2025-12-13 14:13:31 +08:00
export default defineConfig(({ mode }) => ({
// 开发和生产环境都通过nginx代理访问/workcase
base: '/workcase/',
2025-12-11 14:21:36 +08:00
plugins: [
vue({
script: {
defineModel: true,
propsDestructure: true
}
}),
2025-12-13 14:13:31 +08:00
vueJsx(),
federation({
name: 'workcase',
remotes: {
shared: {
type: 'module',
name: 'shared',
2025-12-15 14:50:29 +08:00
entry: 'http://localhost:7000/remoteEntry.js'
2025-12-13 14:13:31 +08:00
}
},
shared: {
vue: {},
'vue-router': {},
'element-plus': {},
axios: {}
}
})
2025-12-11 14:21:36 +08:00
],
define: {
__VUE_OPTIONS_API__: true,
__VUE_PROD_DEVTOOLS__: true,
2025-12-22 17:03:37 +08:00
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: true,
global: 'globalThis'
2025-12-11 14:21:36 +08:00
},
2025-12-06 14:49:46 +08:00
resolve: {
alias: {
'@': resolve(__dirname, 'src')
}
},
server: {
2025-12-15 14:50:29 +08:00
port: 7003,
2025-12-06 14:49:46 +08:00
host: true,
cors: true,
2025-12-13 14:13:31 +08:00
open: '/workcase/', // 开发时自动打开到 /workcase/ 路径
2025-12-20 17:12:42 +08:00
hmr: {
// 修复 base 路径导致的 WebSocket 连接问题
path: '/@vite/client',
port: 7003
},
2025-12-06 14:49:46 +08:00
proxy: {
'/api': {
2025-12-11 16:26:48 +08:00
target: 'http://localhost:8180',
2025-12-06 14:49:46 +08:00
changeOrigin: true,
2025-12-22 17:03:37 +08:00
ws: true, // 启用 WebSocket 代理
2025-12-06 14:49:46 +08:00
rewrite: (path: string) => path.replace(/^\/api/, '')
},
// 代理共享模块请求到 shared 服务
'/shared': {
2025-12-15 14:50:29 +08:00
target: 'http://localhost:7000',
2025-12-06 14:49:46 +08:00
changeOrigin: true
}
}
},
build: {
outDir: 'dist',
sourcemap: true,
rollupOptions: {
output: {
manualChunks: {
'vue-vendor': ['vue', 'vue-router', 'pinia'],
'element-plus': ['element-plus']
}
}
}
}
2025-12-13 14:13:31 +08:00
}))