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