@module-federation/bridge-vue3 0.0.0-next-20240822063818 → 0.0.0-next-20240822101913
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -2
- package/dist/index.cjs.js +3 -3
- package/dist/index.d.ts +8 -6
- package/dist/index.es.js +54 -53
- package/package.json +2 -2
- package/src/provider.ts +46 -37
package/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
# @module-federation/bridge-vue3
|
|
2
2
|
|
|
3
|
-
## 0.0.0-next-
|
|
3
|
+
## 0.0.0-next-20240822101913
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
-
|
|
7
|
+
- 3082116: feat: support module isolated reported
|
|
8
|
+
- @module-federation/bridge-shared@0.0.0-next-20240822101913
|
|
9
|
+
|
|
10
|
+
## 0.5.1
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- @module-federation/bridge-shared@0.5.1
|
|
8
15
|
|
|
9
16
|
## 0.5.0
|
|
10
17
|
|
package/dist/index.cjs.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
2
|
-
`)[2])==null?void 0:
|
|
3
|
-
(${
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("vue"),p=require("vue-router");function b(t){const o=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const e=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(o,n,e.get?e:{enumerable:!0,get:()=>t[n]})}}return o.default=t,Object.freeze(o)}const h=b(u),d=b(p);var y=Object.defineProperty,v=(t,o,n)=>o in t?y(t,o,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[o]=n,i=(t,o,n)=>(v(t,typeof o!="symbol"?o+"":o,n),n);class f{constructor(o){i(this,"name"),i(this,"isDebugEnabled"),i(this,"color"),this.name=o,this.isDebugEnabled=!1,this.color=this.stringToColor(o),typeof window<"u"&&typeof localStorage<"u"&&(this.isDebugEnabled=localStorage.getItem("debug")==="true"),typeof process<"u"&&process.env&&(this.isDebugEnabled=process.env.DEBUG==="true")}log(...o){var n,e;if(this.isDebugEnabled){const r=`color: ${this.color}; font-weight: bold`,m=`%c[${this.name}]`,s=((e=(n=new Error().stack)==null?void 0:n.split(`
|
|
2
|
+
`)[2])==null?void 0:e.trim())||"Stack information not available";typeof console<"u"&&console.debug&&console.debug(m,r,...o,`
|
|
3
|
+
(${s})`)}}stringToColor(o){let n=0;for(let r=0;r<o.length;r++)n=o.charCodeAt(r)+((n<<5)-n);let e="#";for(let r=0;r<3;r++){const m=n>>r*8&255;e+=("00"+m.toString(16)).substr(-2)}return e}}function R(){const t=new PopStateEvent("popstate",{state:window.history.state});window.dispatchEvent(t)}const c=new f("vue3-bridge");function C(t){let o;const n=new Map;return()=>(o||(o={__APP_VERSION__:"0.5.1",render(e){c.log("createBridgeComponent render Info",e);const r=h.createApp(t.rootComponent);n.set(e.dom,r);const m=t.appOptions({basename:e.basename,memoryRoute:e.memoryRoute}),s=e.memoryRoute?d.createMemoryHistory(e.basename):d.createWebHistory(e.basename),a=d.createRouter({...m.router.options,history:s,routes:m.router.getRoutes()});c.log("createBridgeComponent render router info>>>",{name:e.moduleName,router:a}),e.memoryRoute?a.push(e.memoryRoute.entryPath).then(()=>{r.use(a),r.mount(e.dom)}):(r.use(a),r.mount(e.dom))},destroy(e){c.log("createBridgeComponent destroy Info",e);const r=n.get(e==null?void 0:e.dom);r==null||r.unmount()}}),o)}const _=u.defineComponent({name:"RemoteApp",props:{moduleName:String,basename:String,memoryRoute:Object,providerInfo:Function},setup(t){const o=u.ref(null),n=u.ref(null),e=u.ref(""),r=p.useRoute(),m=()=>{var g;const a=(g=t.providerInfo)==null?void 0:g.call(t);n.value=a;const l={name:t.moduleName,dom:o.value,basename:t.basename,memoryRoute:t.memoryRoute};c.log("createRemoteComponent LazyComponent render >>>",l),a.render(l)},s=u.watch(()=>r.path,a=>{a!==r.path&&m(),e.value!==""&&e.value!==a&&(c.log("createRemoteComponent dispatchPopstateEnv >>>",{...t,pathname:r.path}),R()),e.value=a});return u.onMounted(()=>{m()}),u.onBeforeUnmount(()=>{var a;c.log("createRemoteComponent LazyComponent destroy >>>",{...t}),s(),(a=n.value)==null||a.destroy({dom:o.value})}),()=>u.createVNode("div",{ref:o},null)}});function w(t){return u.defineAsyncComponent({__APP_VERSION__:"0.5.1",loader:async()=>{var l;const o=p.useRoute();let n="/";const e=(l=o.matched[0])==null?void 0:l.path;e&&(e.endsWith("/:pathMatch(.*)*")?n=e.replace("/:pathMatch(.*)*",""):n=o.matched[0].path);const r=(t==null?void 0:t.export)||"default";c.log("createRemoteComponent LazyComponent create >>>",{basename:n,info:t});const m=await t.loader(),s=m&&m[Symbol.for("mf_module_id")],a=m[r];if(c.log("createRemoteComponent LazyComponent loadRemote info >>>",{name:s,module:m,exportName:r,basename:n,route:o}),r in m&&typeof a=="function")return{render(){return u.h(_,{moduleName:s,...t,providerInfo:a,basename:n})}};throw new Error("module not found")},loadingComponent:{template:"<div>Loading...</div>"},errorComponent:{template:"<div>Error loading component</div>"},delay:200,timeout:3e3})}exports.createBridgeComponent=C;exports.createRemoteComponent=w;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { ComponentPublicInstance } from 'vue';
|
|
2
2
|
|
|
3
|
-
export declare function createBridgeComponent(bridgeInfo: any): () =>
|
|
3
|
+
export declare function createBridgeComponent(bridgeInfo: any): () => Provider;
|
|
4
|
+
|
|
5
|
+
export declare function createRemoteComponent(info: {
|
|
6
|
+
loader: () => Promise<any>;
|
|
7
|
+
export?: string;
|
|
8
|
+
}): new () => ComponentPublicInstance;
|
|
9
|
+
|
|
10
|
+
declare type Provider = {
|
|
4
11
|
__APP_VERSION__: string;
|
|
5
12
|
render(info: RenderFnParams): void;
|
|
6
13
|
destroy(info: {
|
|
@@ -8,11 +15,6 @@ export declare function createBridgeComponent(bridgeInfo: any): () => {
|
|
|
8
15
|
}): void;
|
|
9
16
|
};
|
|
10
17
|
|
|
11
|
-
export declare function createRemoteComponent(info: {
|
|
12
|
-
loader: () => Promise<any>;
|
|
13
|
-
export?: string;
|
|
14
|
-
}): new () => ComponentPublicInstance;
|
|
15
|
-
|
|
16
18
|
declare interface ProviderParams {
|
|
17
19
|
moduleName?: string;
|
|
18
20
|
basename?: string;
|
package/dist/index.es.js
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
import * as h from "vue";
|
|
2
|
-
import { defineComponent as y, ref as
|
|
2
|
+
import { defineComponent as y, ref as c, watch as b, onMounted as v, onBeforeUnmount as R, createVNode as f, defineAsyncComponent as C, h as w } from "vue";
|
|
3
3
|
import * as d from "vue-router";
|
|
4
4
|
import { useRoute as g } from "vue-router";
|
|
5
|
-
var E = Object.defineProperty, _ = (t, o,
|
|
5
|
+
var E = Object.defineProperty, _ = (t, o, r) => o in t ? E(t, o, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[o] = r, p = (t, o, r) => (_(t, typeof o != "symbol" ? o + "" : o, r), r);
|
|
6
6
|
class S {
|
|
7
7
|
constructor(o) {
|
|
8
8
|
p(this, "name"), p(this, "isDebugEnabled"), p(this, "color"), this.name = o, this.isDebugEnabled = !1, this.color = this.stringToColor(o), typeof window < "u" && typeof localStorage < "u" && (this.isDebugEnabled = localStorage.getItem("debug") === "true"), typeof process < "u" && process.env && (this.isDebugEnabled = process.env.DEBUG === "true");
|
|
9
9
|
}
|
|
10
10
|
log(...o) {
|
|
11
|
-
var
|
|
11
|
+
var r, e;
|
|
12
12
|
if (this.isDebugEnabled) {
|
|
13
|
-
const
|
|
14
|
-
`)[2]) == null ? void 0 :
|
|
15
|
-
typeof console < "u" && console.debug && console.debug(
|
|
13
|
+
const n = `color: ${this.color}; font-weight: bold`, m = `%c[${this.name}]`, s = ((e = (r = new Error().stack) == null ? void 0 : r.split(`
|
|
14
|
+
`)[2]) == null ? void 0 : e.trim()) || "Stack information not available";
|
|
15
|
+
typeof console < "u" && console.debug && console.debug(m, n, ...o, `
|
|
16
16
|
(${s})`);
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
stringToColor(o) {
|
|
20
|
-
let
|
|
21
|
-
for (let
|
|
22
|
-
|
|
23
|
-
let
|
|
24
|
-
for (let
|
|
25
|
-
const
|
|
26
|
-
|
|
20
|
+
let r = 0;
|
|
21
|
+
for (let n = 0; n < o.length; n++)
|
|
22
|
+
r = o.charCodeAt(n) + ((r << 5) - r);
|
|
23
|
+
let e = "#";
|
|
24
|
+
for (let n = 0; n < 3; n++) {
|
|
25
|
+
const m = r >> n * 8 & 255;
|
|
26
|
+
e += ("00" + m.toString(16)).substr(-2);
|
|
27
27
|
}
|
|
28
|
-
return
|
|
28
|
+
return e;
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
function I() {
|
|
@@ -34,34 +34,35 @@ function I() {
|
|
|
34
34
|
}
|
|
35
35
|
const u = new S("vue3-bridge");
|
|
36
36
|
function B(t) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
let o;
|
|
38
|
+
const r = /* @__PURE__ */ new Map();
|
|
39
|
+
return () => (o || (o = {
|
|
40
|
+
__APP_VERSION__: "0.5.1",
|
|
40
41
|
render(e) {
|
|
41
42
|
u.log("createBridgeComponent render Info", e);
|
|
42
43
|
const n = h.createApp(t.rootComponent);
|
|
43
|
-
|
|
44
|
-
const
|
|
44
|
+
r.set(e.dom, n);
|
|
45
|
+
const m = t.appOptions({
|
|
45
46
|
basename: e.basename,
|
|
46
47
|
memoryRoute: e.memoryRoute
|
|
47
|
-
}),
|
|
48
|
-
...
|
|
49
|
-
history:
|
|
50
|
-
routes:
|
|
48
|
+
}), s = e.memoryRoute ? d.createMemoryHistory(e.basename) : d.createWebHistory(e.basename), a = d.createRouter({
|
|
49
|
+
...m.router.options,
|
|
50
|
+
history: s,
|
|
51
|
+
routes: m.router.getRoutes()
|
|
51
52
|
});
|
|
52
53
|
u.log("createBridgeComponent render router info>>>", {
|
|
53
54
|
name: e.moduleName,
|
|
54
|
-
router:
|
|
55
|
-
}), e.memoryRoute ?
|
|
56
|
-
n.use(
|
|
57
|
-
}) : (n.use(
|
|
55
|
+
router: a
|
|
56
|
+
}), e.memoryRoute ? a.push(e.memoryRoute.entryPath).then(() => {
|
|
57
|
+
n.use(a), n.mount(e.dom);
|
|
58
|
+
}) : (n.use(a), n.mount(e.dom));
|
|
58
59
|
},
|
|
59
60
|
destroy(e) {
|
|
60
61
|
u.log("createBridgeComponent destroy Info", e);
|
|
61
|
-
const n =
|
|
62
|
+
const n = r.get(e == null ? void 0 : e.dom);
|
|
62
63
|
n == null || n.unmount();
|
|
63
64
|
}
|
|
64
|
-
});
|
|
65
|
+
}), o);
|
|
65
66
|
}
|
|
66
67
|
const N = /* @__PURE__ */ y({
|
|
67
68
|
name: "RemoteApp",
|
|
@@ -72,30 +73,30 @@ const N = /* @__PURE__ */ y({
|
|
|
72
73
|
providerInfo: Function
|
|
73
74
|
},
|
|
74
75
|
setup(t) {
|
|
75
|
-
const o =
|
|
76
|
+
const o = c(null), r = c(null), e = c(""), n = g(), m = () => {
|
|
76
77
|
var i;
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
const
|
|
78
|
+
const a = (i = t.providerInfo) == null ? void 0 : i.call(t);
|
|
79
|
+
r.value = a;
|
|
80
|
+
const l = {
|
|
80
81
|
name: t.moduleName,
|
|
81
82
|
dom: o.value,
|
|
82
83
|
basename: t.basename,
|
|
83
84
|
memoryRoute: t.memoryRoute
|
|
84
85
|
};
|
|
85
|
-
u.log("createRemoteComponent LazyComponent render >>>",
|
|
86
|
-
}, s = b(() =>
|
|
87
|
-
|
|
86
|
+
u.log("createRemoteComponent LazyComponent render >>>", l), a.render(l);
|
|
87
|
+
}, s = b(() => n.path, (a) => {
|
|
88
|
+
a !== n.path && m(), e.value !== "" && e.value !== a && (u.log("createRemoteComponent dispatchPopstateEnv >>>", {
|
|
88
89
|
...t,
|
|
89
|
-
pathname:
|
|
90
|
-
}), I()),
|
|
90
|
+
pathname: n.path
|
|
91
|
+
}), I()), e.value = a;
|
|
91
92
|
});
|
|
92
93
|
return v(() => {
|
|
93
|
-
|
|
94
|
+
m();
|
|
94
95
|
}), R(() => {
|
|
95
|
-
var
|
|
96
|
+
var a;
|
|
96
97
|
u.log("createRemoteComponent LazyComponent destroy >>>", {
|
|
97
98
|
...t
|
|
98
|
-
}), s(), (
|
|
99
|
+
}), s(), (a = r.value) == null || a.destroy({
|
|
99
100
|
dom: o.value
|
|
100
101
|
});
|
|
101
102
|
}), () => f("div", {
|
|
@@ -105,31 +106,31 @@ const N = /* @__PURE__ */ y({
|
|
|
105
106
|
});
|
|
106
107
|
function D(t) {
|
|
107
108
|
return C({
|
|
108
|
-
__APP_VERSION__: "0.5.
|
|
109
|
+
__APP_VERSION__: "0.5.1",
|
|
109
110
|
//@ts-ignore
|
|
110
111
|
loader: async () => {
|
|
111
|
-
var
|
|
112
|
+
var l;
|
|
112
113
|
const o = g();
|
|
113
|
-
let
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
const
|
|
114
|
+
let r = "/";
|
|
115
|
+
const e = (l = o.matched[0]) == null ? void 0 : l.path;
|
|
116
|
+
e && (e.endsWith("/:pathMatch(.*)*") ? r = e.replace("/:pathMatch(.*)*", "") : r = o.matched[0].path);
|
|
117
|
+
const n = (t == null ? void 0 : t.export) || "default";
|
|
117
118
|
u.log("createRemoteComponent LazyComponent create >>>", {
|
|
118
|
-
basename:
|
|
119
|
+
basename: r,
|
|
119
120
|
info: t
|
|
120
121
|
});
|
|
121
|
-
const
|
|
122
|
+
const m = await t.loader(), s = m && m[Symbol.for("mf_module_id")], a = m[n];
|
|
122
123
|
if (u.log(
|
|
123
124
|
"createRemoteComponent LazyComponent loadRemote info >>>",
|
|
124
|
-
{ name: s, module:
|
|
125
|
-
),
|
|
125
|
+
{ name: s, module: m, exportName: n, basename: r, route: o }
|
|
126
|
+
), n in m && typeof a == "function")
|
|
126
127
|
return {
|
|
127
128
|
render() {
|
|
128
129
|
return w(N, {
|
|
129
130
|
moduleName: s,
|
|
130
131
|
...t,
|
|
131
|
-
providerInfo:
|
|
132
|
-
basename:
|
|
132
|
+
providerInfo: a,
|
|
133
|
+
basename: r
|
|
133
134
|
});
|
|
134
135
|
}
|
|
135
136
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/bridge-vue3",
|
|
3
3
|
"author": "zhouxiao <codingzx@gmail.com>",
|
|
4
|
-
"version": "0.0.0-next-
|
|
4
|
+
"version": "0.0.0-next-20240822101913",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"vue-router": "=3"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@module-federation/bridge-shared": "0.0.0-next-
|
|
29
|
+
"@module-federation/bridge-shared": "0.0.0-next-20240822101913"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@vitejs/plugin-vue": "^5.0.4",
|
package/src/provider.ts
CHANGED
|
@@ -4,50 +4,59 @@ import { RenderFnParams } from '@module-federation/bridge-shared';
|
|
|
4
4
|
import { LoggerInstance } from './utils';
|
|
5
5
|
|
|
6
6
|
declare const __APP_VERSION__: string;
|
|
7
|
+
type Provider = {
|
|
8
|
+
__APP_VERSION__: string;
|
|
9
|
+
render(info: RenderFnParams): void;
|
|
10
|
+
destroy(info: { dom: HTMLElement }): void;
|
|
11
|
+
};
|
|
7
12
|
|
|
8
13
|
export function createBridgeComponent(bridgeInfo: any) {
|
|
14
|
+
let provider: Provider;
|
|
9
15
|
const rootMap = new Map();
|
|
10
16
|
return () => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
if (!provider) {
|
|
18
|
+
provider = {
|
|
19
|
+
__APP_VERSION__,
|
|
20
|
+
render(info: RenderFnParams) {
|
|
21
|
+
LoggerInstance.log(`createBridgeComponent render Info`, info);
|
|
22
|
+
const app = Vue.createApp(bridgeInfo.rootComponent);
|
|
23
|
+
rootMap.set(info.dom, app);
|
|
24
|
+
const appOptions = bridgeInfo.appOptions({
|
|
25
|
+
basename: info.basename,
|
|
26
|
+
memoryRoute: info.memoryRoute,
|
|
27
|
+
});
|
|
21
28
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
const history = info.memoryRoute
|
|
30
|
+
? VueRouter.createMemoryHistory(info.basename)
|
|
31
|
+
: VueRouter.createWebHistory(info.basename);
|
|
32
|
+
const router = VueRouter.createRouter({
|
|
33
|
+
...appOptions.router.options,
|
|
34
|
+
history,
|
|
35
|
+
routes: appOptions.router.getRoutes(),
|
|
36
|
+
});
|
|
30
37
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
LoggerInstance.log(`createBridgeComponent render router info>>>`, {
|
|
39
|
+
name: info.moduleName,
|
|
40
|
+
router,
|
|
41
|
+
});
|
|
42
|
+
// memory route Initializes the route
|
|
43
|
+
if (info.memoryRoute) {
|
|
44
|
+
router.push(info.memoryRoute.entryPath).then(() => {
|
|
45
|
+
app.use(router);
|
|
46
|
+
app.mount(info.dom);
|
|
47
|
+
});
|
|
48
|
+
} else {
|
|
38
49
|
app.use(router);
|
|
39
50
|
app.mount(info.dom);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
},
|
|
51
|
-
};
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
destroy(info: { dom: HTMLElement }) {
|
|
54
|
+
LoggerInstance.log(`createBridgeComponent destroy Info`, info);
|
|
55
|
+
const root = rootMap.get(info?.dom);
|
|
56
|
+
root?.unmount();
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
return provider;
|
|
52
61
|
};
|
|
53
62
|
}
|