web打包问题
This commit is contained in:
@@ -14,8 +14,11 @@ const DEV_SHARED_URL = 'https://localhost:7000/shared/remoteEntry.js'
|
||||
// 生产环境使用相对路径,通过 Nginx 代理访问
|
||||
const PROD_SHARED_URL = '/shared/remoteEntry.js'
|
||||
|
||||
export default defineConfig(({ mode }) => {
|
||||
export default defineConfig(({ mode, command }) => {
|
||||
// dev 和 preview 都需要访问本地 shared 服务
|
||||
// command: 'serve' (dev), 'build', 或通过环境变量判断 preview
|
||||
const isDev = mode === 'development'
|
||||
// preview 模式通过 nginx 代理访问 shared,使用相对路径
|
||||
const sharedEntry = isDev ? DEV_SHARED_URL : PROD_SHARED_URL
|
||||
|
||||
return {
|
||||
@@ -88,19 +91,33 @@ export default defineConfig(({ mode }) => {
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
preview: {
|
||||
port: 7003,
|
||||
host: true,
|
||||
cors: true,
|
||||
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
|
||||
}
|
||||
})(),
|
||||
headers: {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
|
||||
'Access-Control-Allow-Headers': 'Content-Type, Authorization'
|
||||
}
|
||||
},
|
||||
build: {
|
||||
target: 'esnext',
|
||||
outDir: 'dist',
|
||||
sourcemap: true,
|
||||
rollupOptions: {
|
||||
output: {
|
||||
manualChunks: {
|
||||
'vue-vendor': ['vue', 'vue-router', 'pinia'],
|
||||
'element-plus': ['element-plus']
|
||||
}
|
||||
}
|
||||
}
|
||||
sourcemap: true
|
||||
// 注意:不要使用 manualChunks 分割 vue/vue-router/element-plus
|
||||
// 因为它们已经在 Module Federation 的 shared 中声明
|
||||
// 同时使用会导致循环依赖死锁
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user