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

112 lines
3.1 KiB
TypeScript
Raw Normal View History

2025-12-02 15:55:30 +08:00
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
2025-12-11 14:21:36 +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-02 15:55:30 +08:00
/**
2025-12-11 14:21:36 +08:00
* Module Federation @module-federation/vite
* Vite 6 +
2025-12-02 15:55:30 +08:00
*
2025-12-11 14:21:36 +08:00
*
* - Vite
* - dev remoteEntry.js
* - (@/)
* -
2025-12-02 15:55:30 +08:00
*/
export default defineConfig({
2025-12-11 14:21:36 +08:00
plugins: [
vue({
script: {
defineModel: true,
propsDestructure: true
}
}),
vueJsx(),
federation({
name: 'shared',
filename: 'remoteEntry.js',
// 暴露的模块
exposes: {
// 通用组件
'./FileUpload': './src/components/fileupload/FileUpload.vue',
'./DynamicFormItem': './src/components/dynamicFormItem/DynamicFormItem.vue',
// API 模块
'./api': './src/api/index.ts',
'./authAPI': './src/api/auth/auth.ts',
'./fileAPI': './src/api/file/file.ts',
// Utils 模块
'./utils': './src/utils/index.ts',
// Types 模块
'./types': './src/types/index.ts',
// 整体导出
'./components': './src/components/index.ts'
},
// 共享依赖(重要:避免重复加载)
shared: {
vue: {},
'vue-router': {},
'element-plus': {},
'@element-plus/icons-vue': {},
axios: {}
}
})
2025-12-06 14:49:46 +08:00
],
2025-12-11 14:21:36 +08:00
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']
2025-12-02 15:55:30 +08:00
},
2025-12-11 14:21:36 +08:00
build: {
target: 'esnext',
minify: false,
cssCodeSplit: false,
2025-12-02 15:55:30 +08:00
sourcemap: true,
2025-12-11 14:21:36 +08:00
rollupOptions: {
output: {
format: 'es'
}
2025-12-02 15:55:30 +08:00
}
},
2025-12-11 14:21:36 +08:00
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'
}
},
2025-12-02 15:55:30 +08:00
2025-12-11 14:21:36 +08:00
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'
}
2025-12-02 15:55:30 +08:00
}
})