118 lines
3.7 KiB
TypeScript
118 lines
3.7 KiB
TypeScript
import { defineConfig } from 'vite'
|
||
import vue from '@vitejs/plugin-vue'
|
||
import vueJsx from '@vitejs/plugin-vue-jsx'
|
||
import { federation } from '@module-federation/vite'
|
||
import { resolve, dirname } from 'path'
|
||
import { fileURLToPath } from 'url'
|
||
|
||
const __filename = fileURLToPath(import.meta.url)
|
||
const __dirname = dirname(__filename)
|
||
|
||
/**
|
||
* Module Federation 构建配置(@module-federation/vite)
|
||
* 官方维护版本,支持 Vite 6 + 开发模式热更新
|
||
*
|
||
* 优势:
|
||
* - ✅ 完整支持 Vite 开发模式
|
||
* - ✅ dev 模式能生成 remoteEntry.js
|
||
* - ✅ 自动处理内部路径别名 (@/)
|
||
* - ✅ 真正的生产可用版本
|
||
*/
|
||
export default defineConfig({
|
||
plugins: [
|
||
vue({
|
||
script: {
|
||
defineModel: true,
|
||
propsDestructure: true
|
||
}
|
||
}),
|
||
vueJsx(),
|
||
federation({
|
||
name: 'shared',
|
||
filename: 'remoteEntry.js',
|
||
// 暴露的模块
|
||
exposes: {
|
||
// ========== 组件模块 ==========
|
||
'./components': './src/components/index.ts',
|
||
'./components/FileUpload': './src/components/fileupload/FileUpload.vue',
|
||
'./components/DynamicFormItem': './src/components/dynamicFormItem/DynamicFormItem.vue',
|
||
|
||
// ========== API 模块 ==========
|
||
'./api': './src/api/index.ts',
|
||
'./api/auth': './src/api/auth/auth.ts',
|
||
'./api/file': './src/api/file/file.ts',
|
||
|
||
// ========== Utils 工具模块 ==========
|
||
'./utils': './src/utils/index.ts',
|
||
'./utils/device': './src/utils/device.ts',
|
||
'./utils/route': './src/utils/route/index.ts',
|
||
'./utils/route/generator': './src/utils/route/route-generator.ts',
|
||
'./utils/file': './src/utils/file.ts',
|
||
|
||
// ========== Types 类型模块 ==========
|
||
'./types': './src/types/index.ts',
|
||
'./types/base': './src/types/base/index.ts',
|
||
'./types/auth': './src/types/auth/index.ts',
|
||
'./types/file': './src/types/file/index.ts',
|
||
'./types/sys': './src/types/sys/index.ts'
|
||
},
|
||
// 共享依赖(重要:避免重复加载)
|
||
shared: {
|
||
vue: {},
|
||
'vue-router': {},
|
||
'element-plus': {},
|
||
'@element-plus/icons-vue': {},
|
||
axios: {}
|
||
}
|
||
})
|
||
],
|
||
|
||
define: {
|
||
__VUE_OPTIONS_API__: true,
|
||
__VUE_PROD_DEVTOOLS__: true,
|
||
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: true
|
||
},
|
||
|
||
resolve: {
|
||
alias: {
|
||
'@': resolve(__dirname, 'src')
|
||
},
|
||
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
|
||
},
|
||
|
||
build: {
|
||
target: 'esnext',
|
||
minify: false,
|
||
cssCodeSplit: false,
|
||
sourcemap: true,
|
||
rollupOptions: {
|
||
output: {
|
||
format: 'es'
|
||
}
|
||
}
|
||
},
|
||
|
||
server: {
|
||
port: 5000,
|
||
strictPort: true,
|
||
host: true,
|
||
cors: true,
|
||
headers: {
|
||
'Access-Control-Allow-Origin': '*',
|
||
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
|
||
'Access-Control-Allow-Headers': 'Content-Type, Authorization'
|
||
}
|
||
},
|
||
|
||
preview: {
|
||
port: 5000,
|
||
host: true,
|
||
cors: true,
|
||
headers: {
|
||
'Access-Control-Allow-Origin': '*',
|
||
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
|
||
'Access-Control-Allow-Headers': 'Content-Type, Authorization'
|
||
}
|
||
}
|
||
})
|