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

169 lines
6.0 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'
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)
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-27 17:34:19 +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-27 17:34:19 +08:00
// Shared 模块的基础路径(通过 Nginx 代理访问)
base: '/shared/',
2025-12-11 14:21:36 +08:00
plugins: [
vue({
script: {
defineModel: true,
propsDestructure: true
}
}),
vueJsx(),
federation({
name: 'shared',
filename: 'remoteEntry.js',
// 暴露的模块
exposes: {
2025-12-12 18:17:38 +08:00
// ========== 组件模块 ==========
'./components': './src/components/index.ts',
2025-12-20 17:12:42 +08:00
'./components/file/FileUpload': './src/components/file/fileupload/FileUpload.vue',
'./components/file/FileHistory': './src/components/file/fileHistory/FileHistory.vue',
2025-12-12 18:17:38 +08:00
'./components/DynamicFormItem': './src/components/dynamicFormItem/DynamicFormItem.vue',
2025-12-13 14:13:31 +08:00
'./components/iframe/IframeView.vue': './src/components/iframe/IframeView.vue',
2025-12-20 17:12:42 +08:00
'./components/ai/knowledge/DocumentSegment.vue': './src/components/ai/knowledge/documentSegment/DocumentSegment.vue',
'./components/ai/knowledge/DocumentDetail.vue': './src/components/ai/knowledge/documentDetail/DocumentDetail.vue',
2025-12-13 14:13:31 +08:00
2025-12-12 18:17:38 +08:00
// ========== API 模块 ==========
2025-12-11 14:21:36 +08:00
'./api': './src/api/index.ts',
2025-12-12 18:17:38 +08:00
'./api/auth': './src/api/auth/auth.ts',
'./api/file': './src/api/file/file.ts',
2025-12-19 17:34:30 +08:00
'./api/ai': './src/api/ai/index.ts',
2025-12-11 14:21:36 +08:00
2025-12-12 18:17:38 +08:00
// ========== Utils 工具模块 ==========
2025-12-11 14:21:36 +08:00
'./utils': './src/utils/index.ts',
2025-12-12 18:17:38 +08:00
'./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',
2025-12-11 14:21:36 +08:00
2025-12-12 18:17:38 +08:00
// ========== Types 类型模块 ==========
2025-12-11 14:21:36 +08:00
'./types': './src/types/index.ts',
2025-12-12 18:17:38 +08:00
'./types/base': './src/types/base/index.ts',
'./types/auth': './src/types/auth/index.ts',
'./types/file': './src/types/file/index.ts',
2025-12-13 14:13:31 +08:00
'./types/sys': './src/types/sys/index.ts',
2025-12-19 17:34:30 +08:00
'./types/ai': './src/types/ai/index.ts',
2025-12-13 14:13:31 +08:00
// ========== Config 配置模块 ==========
'./config': './src/config/index.ts',
// ========== Layouts 布局模块 ==========
2026-01-08 13:20:40 +08:00
'./layouts': './src/layouts/index.ts',
// ========== Styles 样式模块 ==========
// 直接暴露 SCSS 文件,确保 CSS 在远程加载时被正确注入
'./styles': './src/styles/index.scss'
2025-12-11 14:21:36 +08:00
},
// 共享依赖(重要:避免重复加载)
shared: {
vue: {},
'vue-router': {},
'element-plus': {},
2025-12-20 17:12:42 +08:00
'lucide-vue-next': {},
2025-12-11 14:21:36 +08:00
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,
2026-01-08 13:20:40 +08:00
// 确保 CSS 被提取到单独的文件中
cssMinify: true,
2025-12-11 14:21:36 +08:00
rollupOptions: {
output: {
2026-01-08 13:20:40 +08:00
format: 'es',
2026-01-08 14:01:27 +08:00
// 确保 CSS 文件名固定,不带 hash
2026-01-08 13:20:40 +08:00
assetFileNames: (assetInfo) => {
2026-01-08 14:01:27 +08:00
// CSS 文件使用固定名称,便于在 index.html 中引用
if (assetInfo.name?.endsWith('.css')) {
return 'assets/shared-styles.css'
2026-01-08 13:20:40 +08:00
}
return 'assets/[name]-[hash][extname]'
}
2025-12-11 14:21:36 +08:00
}
2025-12-02 15:55:30 +08:00
}
},
2025-12-11 14:21:36 +08:00
server: {
2025-12-15 14:50:29 +08:00
port: 7000,
2025-12-11 14:21:36 +08:00
strictPort: true,
host: true,
cors: true,
2026-01-02 15:32:04 +08:00
// HTTPS 配置(本地开发用,可选)
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
}
})(),
2025-12-11 14:21:36 +08:00
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type, Authorization'
}
},
2025-12-27 17:34:19 +08:00
2025-12-11 14:21:36 +08:00
preview: {
2025-12-15 14:50:29 +08:00
port: 7000,
2025-12-11 14:21:36 +08:00
host: true,
cors: true,
2026-01-07 15:30:29 +08:00
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
}
})(),
2025-12-11 14:21:36 +08:00
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
}
})