【重要】重构 并实现新的架构
This commit is contained in:
@@ -1,15 +1,13 @@
|
||||
# 请求协议 http or https(建议线上配置证书后,使用https)
|
||||
VITE_PREFIX=http://
|
||||
|
||||
# Nacos 配置中心ip:端口
|
||||
VITE_NACOS_ADDRESS=192.168.31.101:8848
|
||||
# Nacos 配置中心 ip:端口 | 域名
|
||||
#VITE_NACOS_ADDRESS=cluster.nacos.com
|
||||
VITE_NACOS_ADDRESS=192.168.139.84:8848
|
||||
|
||||
# traefik 网关的地址
|
||||
VITE_TRAEFIK_ADDRESS=192.168.31.101
|
||||
|
||||
# 注册到 Nacos 的服务名称(微前端模块名称
|
||||
VITE_SERVER_NAME=app-product
|
||||
|
||||
# 注册到 Nacos 的端口,也是前端运行的端口
|
||||
VITE_SERVER_PORT=1301
|
||||
|
||||
@@ -25,3 +23,4 @@ VITE_MODEL_SHARED_NAME=app-shared
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
# 请求协议 http or https(建议线上配置证书后,使用https)
|
||||
VITE_PREFIX=http://
|
||||
|
||||
# Nacos 配置中心ip:端口
|
||||
VITE_NACOS_ADDRESS=192.168.31.101:8848
|
||||
# Nacos 配置中心 ip:端口 | 域名
|
||||
VITE_NACOS_ADDRESS=192.168.139.84:8848
|
||||
|
||||
# traefik 网关的地址
|
||||
VITE_TRAEFIK_ADDRESS=192.168.31.101
|
||||
|
||||
# 注册到 Nacos 的服务名称(微前端模块名称
|
||||
VITE_SERVER_NAME=app-product
|
||||
@@ -13,7 +11,6 @@ VITE_SERVER_NAME=app-product
|
||||
# 注册到 Nacos 的端口,也是前端运行的端口
|
||||
VITE_SERVER_PORT=1301
|
||||
|
||||
|
||||
#
|
||||
# 说明:项目要调用哪些 微前端 模块
|
||||
# 格式:VITE_MODEL_XXXX_NAME=微前端模块名称(模块 的 开发者提供)
|
||||
@@ -22,6 +19,3 @@ VITE_SERVER_PORT=1301
|
||||
|
||||
# shared 共享资源模块
|
||||
VITE_MODEL_SHARED_NAME=app-shared
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
"type-check": "vue-tsc --build"
|
||||
},
|
||||
"dependencies": {
|
||||
"nacos-federation": "link:../nacos-federation",
|
||||
"pinia": "^3.0.3",
|
||||
"vite-plugin-nacos": "link:../vite-plugin-nacos",
|
||||
"vue": "^3.5.21",
|
||||
"vue-router": "^4.5.1"
|
||||
},
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
import { defineComponent } from 'vue'
|
||||
import { defineComponent, onMounted } from 'vue'
|
||||
|
||||
export default defineComponent({
|
||||
setup() {
|
||||
|
||||
onMounted(() => {
|
||||
console.log("import.meta.env: ", import.meta.env)
|
||||
})
|
||||
|
||||
return () => (
|
||||
<>
|
||||
<div class="order-federation-placeholder">
|
||||
|
||||
@@ -22,7 +22,6 @@ export default defineComponent({
|
||||
|
||||
|
||||
onMounted(() => {
|
||||
|
||||
loadProductList()
|
||||
})
|
||||
|
||||
|
||||
@@ -5,24 +5,18 @@ import vueDevTools from 'vite-plugin-vue-devtools'
|
||||
import federation from '@originjs/vite-plugin-federation';
|
||||
import { fileURLToPath, URL } from "node:url";
|
||||
import { visualizer } from 'rollup-plugin-visualizer';
|
||||
import { reg, init } from 'vite-plugin-nacos';
|
||||
|
||||
export default defineConfig(async ({ mode }) => {
|
||||
const env = loadEnv(mode, process.cwd());
|
||||
|
||||
const { VITE_MODEL_SHARED_URL } = await init(env)
|
||||
return {
|
||||
base: `${ env.VITE_PREFIX }${ env.VITE_TRAEFIK_ADDRESS }/${ env.VITE_SERVER_NAME }`,
|
||||
server: {
|
||||
port: Number(env.VITE_SERVER_PORT),
|
||||
host: '0.0.0.0',
|
||||
strictPort: true,
|
||||
cors: true
|
||||
},
|
||||
plugins: [
|
||||
// nacosRegVitePlugin(),
|
||||
reg(),
|
||||
federation({
|
||||
name: env.VITE_SERVER_NAME,
|
||||
remotes: {
|
||||
shared: `${ env.VITE_PREFIX }${ env.VITE_TRAEFIK_ADDRESS }/${ env.VITE_MODEL_SHARED_NAME }/assets/remoteEntry.js`
|
||||
shared: `${VITE_MODEL_SHARED_URL}/${env.VITE_MODEL_SHARED_NAME}/assets/remoteEntry.js`
|
||||
},
|
||||
exposes: { // 暴露给主应用的资源(按功能分组)
|
||||
'./ProductDomain': './src/domains/product/index.ts', // 领域层(实体、服务、接口等)
|
||||
@@ -50,7 +44,7 @@ export default defineConfig(async ({ mode }) => {
|
||||
cssCodeSplit: true,
|
||||
rollupOptions: {
|
||||
// 关键配置:告诉 Rollup 不要处理模块联邦的导入
|
||||
external: [ 'shared/normalize' ],
|
||||
external: ['shared/normalize'],
|
||||
output: {
|
||||
minifyInternalExports: false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user