@module-federation/bridge-vue3 0.0.0-next-20240822063818 → 0.0.0-next-20240822090000
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 +3 -10
- package/package.json +3 -15
- package/src/provider.ts +46 -37
- package/dist/index.cjs.js +0 -3
- package/dist/index.d.ts +0 -30
- package/dist/index.es.js +0 -151
- /package/{dist → public}/vite.svg +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,18 +1,11 @@
|
|
|
1
1
|
# @module-federation/bridge-vue3
|
|
2
2
|
|
|
3
|
-
## 0.0.0-next-
|
|
3
|
+
## 0.0.0-next-20240822090000
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
|
|
9
|
-
## 0.5.0
|
|
10
|
-
|
|
11
|
-
### Patch Changes
|
|
12
|
-
|
|
13
|
-
- 49d6135: feat(@module-federation/bridge): enhance Bridge capabilities and fix some issues
|
|
14
|
-
- Updated dependencies [49d6135]
|
|
15
|
-
- @module-federation/bridge-shared@0.5.0
|
|
7
|
+
- 3082116: feat: support module isolated reported
|
|
8
|
+
- @module-federation/bridge-shared@0.0.0-next-20240822090000
|
|
16
9
|
|
|
17
10
|
## 0.4.0
|
|
18
11
|
|
package/package.json
CHANGED
|
@@ -1,32 +1,20 @@
|
|
|
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-20240822090000",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
8
|
"type": "module",
|
|
9
|
-
"main": "./dist/index.
|
|
9
|
+
"main": "./dist/index.umd.js",
|
|
10
10
|
"module": "./dist/index.es.js",
|
|
11
11
|
"types": "./dist/index.d.ts",
|
|
12
|
-
"files": [
|
|
13
|
-
"dist/",
|
|
14
|
-
"src/",
|
|
15
|
-
"CHANGELOG.md",
|
|
16
|
-
"LICENSE",
|
|
17
|
-
"package.json",
|
|
18
|
-
"project.json",
|
|
19
|
-
"README.md",
|
|
20
|
-
"tsconfig.json",
|
|
21
|
-
"tsconfig.node.json",
|
|
22
|
-
"vite.config.ts"
|
|
23
|
-
],
|
|
24
12
|
"peerDependencies": {
|
|
25
13
|
"vue": "=3",
|
|
26
14
|
"vue-router": "=3"
|
|
27
15
|
},
|
|
28
16
|
"dependencies": {
|
|
29
|
-
"@module-federation/bridge-shared": "0.0.0-next-
|
|
17
|
+
"@module-federation/bridge-shared": "0.0.0-next-20240822090000"
|
|
30
18
|
},
|
|
31
19
|
"devDependencies": {
|
|
32
20
|
"@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
|
+
interface 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.name,
|
|
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
|
}
|
package/dist/index.cjs.js
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
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.0",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.0",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
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { ComponentPublicInstance } from 'vue';
|
|
2
|
-
|
|
3
|
-
export declare function createBridgeComponent(bridgeInfo: any): () => {
|
|
4
|
-
__APP_VERSION__: string;
|
|
5
|
-
render(info: RenderFnParams): void;
|
|
6
|
-
destroy(info: {
|
|
7
|
-
dom: HTMLElement;
|
|
8
|
-
}): void;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export declare function createRemoteComponent(info: {
|
|
12
|
-
loader: () => Promise<any>;
|
|
13
|
-
export?: string;
|
|
14
|
-
}): new () => ComponentPublicInstance;
|
|
15
|
-
|
|
16
|
-
declare interface ProviderParams {
|
|
17
|
-
moduleName?: string;
|
|
18
|
-
basename?: string;
|
|
19
|
-
memoryRoute?: {
|
|
20
|
-
entryPath: string;
|
|
21
|
-
};
|
|
22
|
-
style?: React.CSSProperties;
|
|
23
|
-
className?: string;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export declare interface RenderFnParams extends ProviderParams {
|
|
27
|
-
dom: HTMLElement;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export { }
|
package/dist/index.es.js
DELETED
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import * as h from "vue";
|
|
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
|
-
import * as d from "vue-router";
|
|
4
|
-
import { useRoute as g } from "vue-router";
|
|
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
|
-
class S {
|
|
7
|
-
constructor(o) {
|
|
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
|
-
}
|
|
10
|
-
log(...o) {
|
|
11
|
-
var e, n;
|
|
12
|
-
if (this.isDebugEnabled) {
|
|
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
|
-
(${s})`);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
stringToColor(o) {
|
|
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
|
-
}
|
|
28
|
-
return n;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
function I() {
|
|
32
|
-
const t = new PopStateEvent("popstate", { state: window.history.state });
|
|
33
|
-
window.dispatchEvent(t);
|
|
34
|
-
}
|
|
35
|
-
const u = new S("vue3-bridge");
|
|
36
|
-
function B(t) {
|
|
37
|
-
const o = /* @__PURE__ */ new Map();
|
|
38
|
-
return () => ({
|
|
39
|
-
__APP_VERSION__: "0.5.0",
|
|
40
|
-
render(e) {
|
|
41
|
-
u.log("createBridgeComponent render Info", e);
|
|
42
|
-
const n = h.createApp(t.rootComponent);
|
|
43
|
-
o.set(e.dom, n);
|
|
44
|
-
const r = t.appOptions({
|
|
45
|
-
basename: e.basename,
|
|
46
|
-
memoryRoute: e.memoryRoute
|
|
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()
|
|
51
|
-
});
|
|
52
|
-
u.log("createBridgeComponent render router info>>>", {
|
|
53
|
-
name: e.moduleName,
|
|
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));
|
|
58
|
-
},
|
|
59
|
-
destroy(e) {
|
|
60
|
-
u.log("createBridgeComponent destroy Info", e);
|
|
61
|
-
const n = o.get(e == null ? void 0 : e.dom);
|
|
62
|
-
n == null || n.unmount();
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
const N = /* @__PURE__ */ y({
|
|
67
|
-
name: "RemoteApp",
|
|
68
|
-
props: {
|
|
69
|
-
moduleName: String,
|
|
70
|
-
basename: String,
|
|
71
|
-
memoryRoute: Object,
|
|
72
|
-
providerInfo: Function
|
|
73
|
-
},
|
|
74
|
-
setup(t) {
|
|
75
|
-
const o = l(null), e = l(null), n = l(""), r = g(), a = () => {
|
|
76
|
-
var i;
|
|
77
|
-
const m = (i = t.providerInfo) == null ? void 0 : i.call(t);
|
|
78
|
-
e.value = m;
|
|
79
|
-
const c = {
|
|
80
|
-
name: t.moduleName,
|
|
81
|
-
dom: o.value,
|
|
82
|
-
basename: t.basename,
|
|
83
|
-
memoryRoute: t.memoryRoute
|
|
84
|
-
};
|
|
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 >>>", {
|
|
88
|
-
...t,
|
|
89
|
-
pathname: r.path
|
|
90
|
-
}), I()), n.value = m;
|
|
91
|
-
});
|
|
92
|
-
return v(() => {
|
|
93
|
-
a();
|
|
94
|
-
}), R(() => {
|
|
95
|
-
var m;
|
|
96
|
-
u.log("createRemoteComponent LazyComponent destroy >>>", {
|
|
97
|
-
...t
|
|
98
|
-
}), s(), (m = e.value) == null || m.destroy({
|
|
99
|
-
dom: o.value
|
|
100
|
-
});
|
|
101
|
-
}), () => f("div", {
|
|
102
|
-
ref: o
|
|
103
|
-
}, null);
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
function D(t) {
|
|
107
|
-
return C({
|
|
108
|
-
__APP_VERSION__: "0.5.0",
|
|
109
|
-
//@ts-ignore
|
|
110
|
-
loader: async () => {
|
|
111
|
-
var c;
|
|
112
|
-
const o = g();
|
|
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";
|
|
117
|
-
u.log("createRemoteComponent LazyComponent create >>>", {
|
|
118
|
-
basename: e,
|
|
119
|
-
info: t
|
|
120
|
-
});
|
|
121
|
-
const a = await t.loader(), s = a && a[Symbol.for("mf_module_id")], m = a[r];
|
|
122
|
-
if (u.log(
|
|
123
|
-
"createRemoteComponent LazyComponent loadRemote info >>>",
|
|
124
|
-
{ name: s, module: a, exportName: r, basename: e, route: o }
|
|
125
|
-
), r in a && typeof m == "function")
|
|
126
|
-
return {
|
|
127
|
-
render() {
|
|
128
|
-
return w(N, {
|
|
129
|
-
moduleName: s,
|
|
130
|
-
...t,
|
|
131
|
-
providerInfo: m,
|
|
132
|
-
basename: e
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
throw new Error("module not found");
|
|
137
|
-
},
|
|
138
|
-
loadingComponent: {
|
|
139
|
-
template: "<div>Loading...</div>"
|
|
140
|
-
},
|
|
141
|
-
errorComponent: {
|
|
142
|
-
template: "<div>Error loading component</div>"
|
|
143
|
-
},
|
|
144
|
-
delay: 200,
|
|
145
|
-
timeout: 3e3
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
export {
|
|
149
|
-
B as createBridgeComponent,
|
|
150
|
-
D as createRemoteComponent
|
|
151
|
-
};
|
|
File without changes
|