服务打包初步结构
This commit is contained in:
@@ -9,80 +9,93 @@ import fs from 'fs'
|
||||
const __filename = fileURLToPath(import.meta.url)
|
||||
const __dirname = dirname(__filename)
|
||||
|
||||
export default defineConfig({
|
||||
// Platform 应用的基础路径
|
||||
base: '/platform/',
|
||||
|
||||
plugins: [
|
||||
vue({
|
||||
script: {
|
||||
defineModel: true,
|
||||
propsDestructure: true
|
||||
}
|
||||
}),
|
||||
vueJsx(),
|
||||
federation({
|
||||
name: 'platform',
|
||||
remotes: {
|
||||
shared: {
|
||||
type: 'module',
|
||||
name: 'shared',
|
||||
entry: 'https://org.xyzh.yslg/shared/remoteEntry.js'
|
||||
// 开发环境 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: '/platform/',
|
||||
|
||||
plugins: [
|
||||
vue({
|
||||
script: {
|
||||
defineModel: true,
|
||||
propsDestructure: true
|
||||
}
|
||||
}),
|
||||
vueJsx(),
|
||||
federation({
|
||||
name: 'platform',
|
||||
remotes: {
|
||||
shared: {
|
||||
type: 'module',
|
||||
name: 'shared',
|
||||
entry: sharedEntry
|
||||
}
|
||||
},
|
||||
shared: {
|
||||
vue: {},
|
||||
'vue-router': {},
|
||||
'element-plus': {},
|
||||
axios: {}
|
||||
}
|
||||
})
|
||||
],
|
||||
|
||||
define: {
|
||||
__VUE_OPTIONS_API__: true,
|
||||
__VUE_PROD_DEVTOOLS__: true,
|
||||
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: true
|
||||
},
|
||||
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': resolve(__dirname, 'src')
|
||||
}
|
||||
},
|
||||
|
||||
server: {
|
||||
port: 7001,
|
||||
host: true,
|
||||
cors: true,
|
||||
open: '/',
|
||||
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: 7001
|
||||
},
|
||||
shared: {
|
||||
vue: {},
|
||||
'vue-router': {},
|
||||
'element-plus': {},
|
||||
axios: {}
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: 'http://localhost:8180',
|
||||
changeOrigin: true,
|
||||
rewrite: (path: string) => path.replace(/^\/api/, '')
|
||||
}
|
||||
}
|
||||
})
|
||||
],
|
||||
|
||||
define: {
|
||||
__VUE_OPTIONS_API__: true,
|
||||
__VUE_PROD_DEVTOOLS__: true,
|
||||
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: true
|
||||
},
|
||||
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': resolve(__dirname, 'src')
|
||||
}
|
||||
},
|
||||
|
||||
server: {
|
||||
port: 7001,
|
||||
host: true,
|
||||
cors: true,
|
||||
open: '/', // 开发时自动打开到根路径
|
||||
// HTTPS 配置(使用 mkcert 生成的本地开发证书)
|
||||
https: {
|
||||
key: fs.readFileSync('C:/Users/FK05/443/localhost+3-key.pem'),
|
||||
cert: fs.readFileSync('C:/Users/FK05/443/localhost+3.pem')
|
||||
},
|
||||
hmr: {
|
||||
// 修复 base 路径导致的 WebSocket 连接问题
|
||||
path: '/@vite/client',
|
||||
port: 7001
|
||||
},
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: 'http://localhost:8180',
|
||||
changeOrigin: true,
|
||||
rewrite: (path: string) => path.replace(/^\/api/, '')
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
build: {
|
||||
outDir: 'dist',
|
||||
sourcemap: true,
|
||||
rollupOptions: {
|
||||
output: {
|
||||
manualChunks: {
|
||||
'vue-vendor': ['vue', 'vue-router', 'pinia'],
|
||||
'element-plus': ['element-plus']
|
||||
|
||||
build: {
|
||||
outDir: 'dist',
|
||||
sourcemap: true,
|
||||
rollupOptions: {
|
||||
output: {
|
||||
manualChunks: {
|
||||
'vue-vendor': ['vue', 'vue-router', 'pinia'],
|
||||
'element-plus': ['element-plus']
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user