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

107 lines
2.4 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'
2025-12-27 17:34:19 +08:00
import fs from 'fs'
2025-12-06 14:49:46 +08:00
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
2026-01-02 14:56:14 +08:00
// 开发环境 shared 模块地址
const DEV_SHARED_URL = 'https://localhost:7000/shared/mf-manifest.json'
// 生产环境使用相对路径,通过 Nginx 代理访问
const PROD_SHARED_URL = '/shared/mf-manifest.json'
export default defineConfig(({ mode }) => {
const isDev = mode === 'development'
const sharedEntry = isDev ? DEV_SHARED_URL : PROD_SHARED_URL
return {
base: '/workcase/',
plugins: [
vue({
script: {
defineModel: true,
propsDestructure: true
}
}),
vueJsx(),
federation({
name: 'workcase',
remotes: {
shared: {
type: 'module',
name: 'shared',
entry: sharedEntry
}
},
2025-12-13 14:13:31 +08:00
shared: {
2026-01-02 14:56:14 +08:00
vue: {},
'vue-router': {},
'element-plus': {},
axios: {}
2025-12-13 14:13:31 +08:00
}
2026-01-02 14:56:14 +08:00
})
],
define: {
__VUE_OPTIONS_API__: true,
__VUE_PROD_DEVTOOLS__: true,
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: true,
global: 'globalThis'
2025-12-27 17:34:19 +08:00
},
2026-01-02 14:56:14 +08:00
resolve: {
alias: {
'@': resolve(__dirname, 'src')
}
2025-12-20 17:12:42 +08:00
},
2026-01-02 14:56:14 +08:00
server: {
port: 7003,
host: true,
cors: true,
open: '/workcase/',
https: (() => {
try {
return {
key: fs.readFileSync('C:/Users/FK05/443/localhost+3-key.pem'),
cert: fs.readFileSync('C:/Users/FK05/443/localhost+3.pem')
}
} catch {
return undefined
}
})(),
hmr: {
path: '/@vite/client',
port: 7003
},
proxy: {
'/api': {
target: 'http://localhost:8180',
changeOrigin: true,
ws: true,
rewrite: (path: string) => path.replace(/^\/api/, '')
}
2025-12-06 14:49:46 +08:00
}
2026-01-02 14:56:14 +08:00
},
build: {
2026-01-02 15:50:20 +08:00
target: 'esnext',
2026-01-02 14:56:14 +08:00
outDir: 'dist',
sourcemap: true,
rollupOptions: {
output: {
manualChunks: {
'vue-vendor': ['vue', 'vue-router', 'pinia'],
'element-plus': ['element-plus']
}
2025-12-06 14:49:46 +08:00
}
}
}
}
2026-01-02 14:56:14 +08:00
})