@fulgurjs/federation 5.2.5 → 5.3.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/DESIGN.md +7 -0
- package/README.en.md +86 -4
- package/README.md +125 -3
- package/dist/bridge-app-react.cjs +185 -0
- package/dist/bridge-app-react.d.cts +37 -0
- package/dist/bridge-app-react.d.ts +37 -0
- package/dist/bridge-app-react.js +115 -0
- package/dist/bridge-app-vue.cjs +111 -0
- package/dist/bridge-app-vue.d.cts +34 -0
- package/dist/bridge-app-vue.d.ts +34 -0
- package/dist/bridge-app-vue.js +51 -0
- package/dist/bridge-core-6uLJiMVa.d.ts +42 -0
- package/dist/bridge-core.cjs +224 -0
- package/dist/bridge-core.d.cts +51 -0
- package/dist/bridge-core.d.ts +51 -0
- package/dist/bridge-core.js +21 -0
- package/dist/bridge-errors.cjs +114 -0
- package/dist/bridge-errors.d.cts +36 -0
- package/dist/bridge-errors.d.ts +36 -0
- package/dist/bridge-errors.js +15 -0
- package/dist/bridge-host-react-C55RmGll.d.ts +35 -0
- package/dist/bridge-host-react.cjs +392 -0
- package/dist/bridge-host-react.d.cts +45 -0
- package/dist/bridge-host-react.d.ts +45 -0
- package/dist/bridge-host-react.js +183 -0
- package/dist/bridge-host-vue-BAxDKqGH.d.ts +32 -0
- package/dist/bridge-host-vue.cjs +426 -0
- package/dist/bridge-host-vue.d.cts +39 -0
- package/dist/bridge-host-vue.d.ts +39 -0
- package/dist/bridge-host-vue.js +211 -0
- package/dist/bridge-react.d.ts +12 -0
- package/dist/bridge-react.js +3 -0
- package/dist/bridge-vue.d.ts +8 -0
- package/dist/bridge-vue.js +3 -0
- package/dist/bridge.d.ts +16 -0
- package/dist/bridge.js +5 -0
- package/dist/chunk-E55P4TIY.js +76 -0
- package/dist/chunk-EH34L46P.js +207 -0
- package/dist/chunk-FVYGSLAQ.js +179 -0
- package/dist/chunk-LWJBHUJQ.js +114 -0
- package/dist/chunk-OF2JCXTZ.js +15 -0
- package/dist/chunk-TSYLDY6H.js +64 -0
- package/dist/chunk-UJFCPQGN.js +1210 -0
- package/dist/context.js +8 -64
- package/dist/index.cjs +84 -8
- package/dist/index.js +84 -8
- package/dist/react.d.ts +44 -2
- package/dist/react.js +2 -0
- package/dist/runtime-entry.d.ts +41 -2
- package/dist/runtime-entry.js +1 -1
- package/dist/runtime.js +1 -1
- package/dist/vue.js +2 -0
- package/docs/webpack-mf-/345/257/271/347/205/247/344/270/216/347/274/272/345/217/243.md +1 -1
- package/docs//350/277/201/347/247/273/346/214/207/345/215/227.md +1 -1
- package/examples/README.en.md +20 -0
- package/examples/README.md +20 -0
- package/examples/bridge/README.md +36 -0
- package/examples/bridge/react-host/README.md +23 -0
- package/examples/bridge/react-host/fulgurjs.config.ts +20 -0
- package/examples/bridge/react-host/index.html +11 -0
- package/examples/bridge/react-host/package-lock.json +2457 -0
- package/examples/bridge/react-host/package.json +24 -0
- package/examples/bridge/react-host/src/env.d.ts +7 -0
- package/examples/bridge/react-host/src/host-session.ts +26 -0
- package/examples/bridge/react-host/src/main.tsx +62 -0
- package/examples/bridge/react-host/tsconfig.json +13 -0
- package/examples/bridge/react-host/vite.config.ts +9 -0
- package/examples/bridge/react-remote/README.md +20 -0
- package/examples/bridge/react-remote/fulgurjs.config.ts +17 -0
- package/examples/bridge/react-remote/index.html +11 -0
- package/examples/bridge/react-remote/package-lock.json +2382 -0
- package/examples/bridge/react-remote/package.json +24 -0
- package/examples/bridge/react-remote/src/bridge.tsx +66 -0
- package/examples/bridge/react-remote/src/env.d.ts +7 -0
- package/examples/bridge/react-remote/src/main.tsx +7 -0
- package/examples/bridge/react-remote/tsconfig.json +13 -0
- package/examples/bridge/react-remote/vite.config.ts +9 -0
- package/examples/bridge/vue-host/README.md +24 -0
- package/examples/bridge/vue-host/fulgurjs.config.ts +22 -0
- package/examples/bridge/vue-host/index.html +11 -0
- package/examples/bridge/vue-host/package-lock.json +1885 -0
- package/examples/bridge/vue-host/package.json +24 -0
- package/examples/bridge/vue-host/src/App.vue +70 -0
- package/examples/bridge/vue-host/src/env.d.ts +7 -0
- package/examples/bridge/vue-host/src/host-session.ts +29 -0
- package/examples/bridge/vue-host/src/main.ts +4 -0
- package/examples/bridge/vue-host/tsconfig.json +13 -0
- package/examples/bridge/vue-host/vite.config.ts +9 -0
- package/examples/bridge/vue-remote/README.md +19 -0
- package/examples/bridge/vue-remote/fulgurjs.config.ts +16 -0
- package/examples/bridge/vue-remote/index.html +11 -0
- package/examples/bridge/vue-remote/package-lock.json +1856 -0
- package/examples/bridge/vue-remote/package.json +21 -0
- package/examples/bridge/vue-remote/src/App.vue +12 -0
- package/examples/bridge/vue-remote/src/bridge.ts +57 -0
- package/examples/bridge/vue-remote/src/env.d.ts +7 -0
- package/examples/bridge/vue-remote/src/main.ts +15 -0
- package/examples/bridge/vue-remote/tsconfig.json +13 -0
- package/examples/bridge/vue-remote/vite.config.ts +9 -0
- package/package.json +43 -2
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "fulgurjs-demo-bridge-vue-host",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "vite --port 5314 --strictPort",
|
|
8
|
+
"build": "vite build",
|
|
9
|
+
"preview": "vite preview --port 5314 --strictPort"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@fulgurjs/federation": "5.3.0",
|
|
13
|
+
"vue": "^3.5.13",
|
|
14
|
+
"react": "^19.1.0",
|
|
15
|
+
"react-dom": "^19.1.0"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@types/react": "^19.1.0",
|
|
19
|
+
"@types/react-dom": "^19.1.0",
|
|
20
|
+
"@vitejs/plugin-vue": "^5.2.1",
|
|
21
|
+
"typescript": "^5.8.0",
|
|
22
|
+
"vite": "^6.3.5"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* Vue 宿主 × React 桥接子应用(examples 版,含全部关键语义注释)。
|
|
4
|
+
* 先启动 examples/bridge/react-remote(5303)再启动本宿主。
|
|
5
|
+
*/
|
|
6
|
+
import { ref } from 'vue'
|
|
7
|
+
import { clearAppContext } from '@fulgurjs/federation/runtime'
|
|
8
|
+
import { createVueBridgeApp } from '@fulgurjs/federation/bridge/vue'
|
|
9
|
+
import { getLatestHostContext, login, logout } from './host-session'
|
|
10
|
+
|
|
11
|
+
// 工厂选项:retries 透传 loadRemote;getContext 在每次实际加载前同步取最新快照
|
|
12
|
+
const RemoteReactApp = createVueBridgeApp('bridge-react-remote/bridge', {
|
|
13
|
+
retries: 1,
|
|
14
|
+
getContext: () => getLatestHostContext(),
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
// sessionKey 是桥接控制参数(非敏感登录代次 ID),不是业务 props
|
|
18
|
+
const sessionKey = ref<string | null>('login-1-alice')
|
|
19
|
+
const userName = ref('Alice')
|
|
20
|
+
const label = ref('来自 Vue 宿主')
|
|
21
|
+
const readyCount = ref(0)
|
|
22
|
+
|
|
23
|
+
function handleReady(): void {
|
|
24
|
+
readyCount.value++
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function nextFrame(): Promise<void> {
|
|
28
|
+
return new Promise((r) => requestAnimationFrame(() => r(null)))
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// 换账号推荐顺序(§4.3):受控 prop 置 null → 等卸载 → clearAppContext 清 A 残留
|
|
32
|
+
// → 登录 B → 更新受控 prop 触发新代次(getContext + loadRemote + onSession 全走一遍)
|
|
33
|
+
async function switchUser(): Promise<void> {
|
|
34
|
+
sessionKey.value = null
|
|
35
|
+
await nextFrame()
|
|
36
|
+
clearAppContext()
|
|
37
|
+
login('login-2-bob', { id: 2, name: 'Bob' })
|
|
38
|
+
userName.value = 'Bob'
|
|
39
|
+
sessionKey.value = 'login-2-bob'
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// 登出:prop 置 null → 桥接立即卸载且不再请求 → 宿主清理全局 context
|
|
43
|
+
async function doLogout(): Promise<void> {
|
|
44
|
+
sessionKey.value = null
|
|
45
|
+
await nextFrame()
|
|
46
|
+
clearAppContext()
|
|
47
|
+
logout()
|
|
48
|
+
userName.value = ''
|
|
49
|
+
}
|
|
50
|
+
</script>
|
|
51
|
+
|
|
52
|
+
<template>
|
|
53
|
+
<div style="font-family: sans-serif; padding: 16px; max-width: 720px">
|
|
54
|
+
<h1>Vue 宿主 × React 子应用(@fulgurjs/federation/bridge/vue)</h1>
|
|
55
|
+
<p data-testid="demo-session">会话:{{ sessionKey ?? '未登录' }}({{ userName || '—' }})· onReady 次数:{{ readyCount }}</p>
|
|
56
|
+
|
|
57
|
+
<p>
|
|
58
|
+
<button data-testid="demo-switch" @click="switchUser">切换到 Bob(clearAppContext → 重挂)</button>
|
|
59
|
+
<button data-testid="demo-logout" @click="doLogout">登出(sessionKey → null)</button>
|
|
60
|
+
</p>
|
|
61
|
+
|
|
62
|
+
<!-- 外层元素控制桥接区域外观;appProps 是挂载时浅拷贝快照,换引用不重挂,重挂用 :key -->
|
|
63
|
+
<section style="margin-top: 12px">
|
|
64
|
+
<RemoteReactApp
|
|
65
|
+
:session-key="sessionKey"
|
|
66
|
+
:app-props="{ label, onReady: handleReady }"
|
|
67
|
+
/>
|
|
68
|
+
</section>
|
|
69
|
+
</div>
|
|
70
|
+
</template>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 宿主自有会话源(示例实现):返回「当前登录用户」的完整 AppContext 快照。
|
|
3
|
+
* 要求(任务书 §4.3):纯同步、无副作用、不调 provideAppContext、不返回 Promise。
|
|
4
|
+
* 真实项目里通常读登录 store / token 管理器——只要保持「同步快照 getter」语义即可。
|
|
5
|
+
*/
|
|
6
|
+
export interface HostSession {
|
|
7
|
+
key: string | null
|
|
8
|
+
user: { id: number; name: string }
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
let current: HostSession = { key: 'login-1-alice', user: { id: 1, name: 'Alice' } }
|
|
12
|
+
|
|
13
|
+
export function getLatestHostContext(): Record<string, unknown> & { sessionKey: string } {
|
|
14
|
+
if (current.key === null) throw new Error('已登出:此刻不应有桥接代次请求 context')
|
|
15
|
+
return {
|
|
16
|
+
sessionKey: current.key,
|
|
17
|
+
user: current.user,
|
|
18
|
+
// 取最新 token 用拉取式函数引用,防止快照过期(README §9)
|
|
19
|
+
getToken: () => `token-for-${current.key}`,
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function login(key: string, user: { id: number; name: string }): void {
|
|
24
|
+
current = { key, user }
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function logout(): void {
|
|
28
|
+
current = { key: null, user: { id: 0, name: '' } }
|
|
29
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"jsx": "preserve",
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
"noEmit": true,
|
|
10
|
+
"types": ["vite/client"]
|
|
11
|
+
},
|
|
12
|
+
"include": ["src", "fulgurjs.config.ts", "vite.config.ts"]
|
|
13
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { defineConfig } from 'vite'
|
|
2
|
+
import vue from '@vitejs/plugin-vue'
|
|
3
|
+
import { federation } from '@fulgurjs/federation'
|
|
4
|
+
import fulgurjsConfig from './fulgurjs.config'
|
|
5
|
+
|
|
6
|
+
export default defineConfig(({ command }) => ({
|
|
7
|
+
base: command === 'build' ? '/bridge-vue-host/' : undefined,
|
|
8
|
+
plugins: [vue(), federation(fulgurjsConfig)],
|
|
9
|
+
}))
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# bridge-vue-remote — Vue 桥接子应用示例
|
|
2
|
+
|
|
3
|
+
`@fulgurjs/federation` 跨框架桥接的 **Vue 3 子应用**侧示例:以 `defineBridgeApp`(`@fulgurjs/federation/runtime`)导出 `mount/unmount` 契约,可被 **React 宿主**(配合 `examples/bridge/react-host`)整站挂载。
|
|
4
|
+
|
|
5
|
+
## 运行
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install
|
|
9
|
+
npm run dev # http://localhost:5313(独立运行态)
|
|
10
|
+
npm run build # 产出 /bridge-vue-remote/ 子路径产物
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## 关键点
|
|
14
|
+
|
|
15
|
+
- `src/bridge.ts`:`defineBridgeApp((props) => VueApp)` 工厂——自行装配 memory 路由(vue-router),作为 `./bridge` expose 的默认导出。
|
|
16
|
+
- 子应用只安装并共享 `vue`(+ `vue-router` 为直接依赖),**不安装 React**。
|
|
17
|
+
- `sessionKey`/`getContext` 等会话语义由宿主侧控制,见 `examples/bridge/react-host`。
|
|
18
|
+
|
|
19
|
+
配套阅读:根目录 README §8.2「跨框架桥接 API — /bridge」。
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { FederationOptions } from '@fulgurjs/federation'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Vue 子应用联邦配置:`./bridge` expose = defineBridgeApp 契约模块(任务书 §3.3)。
|
|
5
|
+
* 子应用只安装并共享自己的框架(vue),不为桥接安装对方框架。
|
|
6
|
+
*/
|
|
7
|
+
export default {
|
|
8
|
+
name: 'bridge-vue-remote',
|
|
9
|
+
filename: 'fulgurjs-remoteEntry.js',
|
|
10
|
+
exposes: {
|
|
11
|
+
'./bridge': './src/bridge.ts',
|
|
12
|
+
},
|
|
13
|
+
shared: {
|
|
14
|
+
vue: { singleton: true, requiredVersion: '^3.4.0' },
|
|
15
|
+
},
|
|
16
|
+
} satisfies FederationOptions
|