@module-federation/bridge-vue3 0.3.5 → 0.5.0
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 +14 -0
- package/dist/index.cjs.js +3 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.es.js +151 -0
- package/package.json +15 -3
- /package/{public → dist}/vite.svg +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @module-federation/bridge-vue3
|
|
2
2
|
|
|
3
|
+
## 0.5.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 49d6135: feat(@module-federation/bridge): enhance Bridge capabilities and fix some issues
|
|
8
|
+
- Updated dependencies [49d6135]
|
|
9
|
+
- @module-federation/bridge-shared@0.5.0
|
|
10
|
+
|
|
11
|
+
## 0.4.0
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- @module-federation/bridge-shared@0.4.0
|
|
16
|
+
|
|
3
17
|
## 0.3.5
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -0,0 +1,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 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(u),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}]`,s=((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
|
+
(${s})`)}}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),s=d.createRouter({...r.router.options,history:a,routes:r.router.getRoutes()});c.log("createBridgeComponent render router info>>>",{name:e.name,router:s}),e.memoryRoute?s.push(e.memoryRoute.entryPath).then(()=>{n.use(s),n.mount(e.dom)}):(n.use(s),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 _=u.defineComponent({name:"RemoteApp",props:{moduleName:String,basename:String,memoryRoute:Object,providerInfo:Function},setup(t){const o=u.ref(null),e=u.ref(null),n=u.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)},s=u.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 u.onMounted(()=>{a()}),u.onBeforeUnmount(()=>{var m;c.log("createRemoteComponent LazyComponent destroy >>>",{...t}),s(),(m=e.value)==null||m.destroy({dom:o.value})}),()=>u.createVNode("div",{ref:o},null)}});function w(t){return u.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(),s=a&&a[Symbol.for("mf_module_id")],m=a[r];if(c.log("createRemoteComponent LazyComponent loadRemote info >>>",{name:s,module:a,exportName:r,basename:e,route:o}),r in a&&typeof m=="function")return{render(){return u.h(_,{moduleName:s,...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
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
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.name,
|
|
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 P = /* @__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(P, {
|
|
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
|
+
};
|
package/package.json
CHANGED
|
@@ -1,20 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/bridge-vue3",
|
|
3
3
|
"author": "zhouxiao <codingzx@gmail.com>",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.5.0",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
8
|
"type": "module",
|
|
9
|
-
"main": "./dist/index.
|
|
9
|
+
"main": "./dist/index.cjs.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
|
+
],
|
|
12
24
|
"peerDependencies": {
|
|
13
25
|
"vue": "=3",
|
|
14
26
|
"vue-router": "=3"
|
|
15
27
|
},
|
|
16
28
|
"dependencies": {
|
|
17
|
-
"@module-federation/bridge-shared": "0.
|
|
29
|
+
"@module-federation/bridge-shared": "0.5.0"
|
|
18
30
|
},
|
|
19
31
|
"devDependencies": {
|
|
20
32
|
"@vitejs/plugin-vue": "^5.0.4",
|
|
File without changes
|