@fulgurjs/federation 5.2.4 → 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 +18 -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/examples/react/host/package-lock.json +3 -3
- package/examples/react/host/package.json +1 -1
- package/examples/react/remote/package-lock.json +3 -3
- package/examples/react/remote/package.json +1 -1
- package/examples/react/remote/vite.config.ts +3 -2
- package/examples/vue/README.md +1 -1
- package/examples/vue/host/package-lock.json +3 -3
- package/examples/vue/host/package.json +1 -1
- package/examples/vue/remote/README.md +1 -1
- package/examples/vue/remote/package-lock.json +3 -3
- package/examples/vue/remote/package.json +1 -1
- package/examples/vue/remote/vite.config.ts +3 -2
- package/package.json +43 -2
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "fulgurjs-demo-bridge-react-remote",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "vite --port 5303 --strictPort",
|
|
8
|
+
"build": "vite build",
|
|
9
|
+
"preview": "vite preview --port 5303 --strictPort"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@fulgurjs/federation": "5.3.0",
|
|
13
|
+
"react": "^19.1.0",
|
|
14
|
+
"react-dom": "^19.1.0",
|
|
15
|
+
"react-router-dom": "^7.1.0"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@types/react": "^19.1.0",
|
|
19
|
+
"@types/react-dom": "^19.1.0",
|
|
20
|
+
"@vitejs/plugin-react": "^5.0.0",
|
|
21
|
+
"typescript": "^5.8.0",
|
|
22
|
+
"vite": "^6.3.5"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React 子应用桥接契约(./bridge expose 的默认导出,任务书 §3.3)。
|
|
3
|
+
*
|
|
4
|
+
* defineBridgeApp 工厂接收 props 快照、返回 ReactElement;
|
|
5
|
+
* createRoot/首次提交探测/unmount 由契约实现负责(react-dom/client 在实际 mount 时按需加载)。
|
|
6
|
+
*/
|
|
7
|
+
import { useEffect, useState } from 'react'
|
|
8
|
+
import { MemoryRouter, Route, Routes, useLocation, useNavigate } from 'react-router-dom'
|
|
9
|
+
import { defineBridgeApp } from '@fulgurjs/federation/react'
|
|
10
|
+
|
|
11
|
+
/** 挂载即回调(宿主验证函数引用跨 root 传递) */
|
|
12
|
+
function OnReady({ onReady }: { onReady?: () => void }) {
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
onReady?.()
|
|
15
|
+
// 挂载回调只触发一次
|
|
16
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
17
|
+
}, [])
|
|
18
|
+
return null
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function Counter() {
|
|
22
|
+
const [n, setN] = useState(0)
|
|
23
|
+
return (
|
|
24
|
+
<button data-testid="demo-react-counter" onClick={() => setN(n + 1)}>
|
|
25
|
+
本地状态:{n}
|
|
26
|
+
</button>
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function Shell(props: Record<string, unknown>) {
|
|
31
|
+
const location = useLocation()
|
|
32
|
+
const navigate = useNavigate()
|
|
33
|
+
return (
|
|
34
|
+
<div style={{ border: '1px solid #61dafb', borderRadius: 8, padding: 12, fontFamily: 'sans-serif' }}>
|
|
35
|
+
<p style={{ margin: '0 0 6px', fontWeight: 600, color: '#0b7285' }}>React 子应用</p>
|
|
36
|
+
<p data-testid="demo-react-props" style={{ margin: '0 0 6px' }}>
|
|
37
|
+
{`appProps.label = ${(props as any).label || '(未传)'}`}
|
|
38
|
+
</p>
|
|
39
|
+
<p data-testid="demo-react-route" style={{ margin: '0 0 8px' }}>{`memory 路由:${location.pathname}`}</p>
|
|
40
|
+
<nav style={{ marginBottom: 8 }}>
|
|
41
|
+
<button style={{ marginRight: 8 }} onClick={() => navigate('/')}>首页</button>
|
|
42
|
+
<button onClick={() => navigate('/about')}>关于</button>
|
|
43
|
+
</nav>
|
|
44
|
+
<Counter />
|
|
45
|
+
<Routes>
|
|
46
|
+
<Route path="/" element={<p data-testid="demo-react-page">页面:首页</p>} />
|
|
47
|
+
<Route path="/about" element={<p data-testid="demo-react-page">页面:关于</p>} />
|
|
48
|
+
</Routes>
|
|
49
|
+
</div>
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function App() {
|
|
54
|
+
return (
|
|
55
|
+
<MemoryRouter>
|
|
56
|
+
<Shell />
|
|
57
|
+
</MemoryRouter>
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export default defineBridgeApp((props) => (
|
|
62
|
+
<MemoryRouter>
|
|
63
|
+
<OnReady onReady={(props as any).onReady} />
|
|
64
|
+
<Shell {...props} />
|
|
65
|
+
</MemoryRouter>
|
|
66
|
+
))
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { createElement } from 'react'
|
|
2
|
+
import { createRoot } from 'react-dom/client'
|
|
3
|
+
import { App } from './bridge'
|
|
4
|
+
|
|
5
|
+
// 独立运行入口:单独开发/调试子应用自身时使用。
|
|
6
|
+
// 被桥接宿主消费时走 fulgurjs-remoteEntry.js 容器入口与 ./bridge 契约,与本文件无关。
|
|
7
|
+
createRoot(document.getElementById('root')!).render(createElement(App))
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"jsx": "react-jsx",
|
|
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 react from '@vitejs/plugin-react'
|
|
3
|
+
import { federation } from '@fulgurjs/federation'
|
|
4
|
+
import fulgurjsConfig from './fulgurjs.config'
|
|
5
|
+
|
|
6
|
+
export default defineConfig(({ command }) => ({
|
|
7
|
+
base: command === 'build' ? '/bridge-react-remote/' : undefined,
|
|
8
|
+
plugins: [react(), federation(fulgurjsConfig)],
|
|
9
|
+
}))
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# bridge-vue-host — Vue 宿主 × React 桥接子应用示例
|
|
2
|
+
|
|
3
|
+
`@fulgurjs/federation` 跨框架桥接的 **Vue 3 宿主**侧示例:用 `createVueBridgeApp`(`@fulgurjs/federation/bridge/vue`)把 `bridge-react-remote/bridge` 作为受控组件挂载。
|
|
4
|
+
|
|
5
|
+
## 运行
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# 1) 先启动 React 子应用(5303)
|
|
9
|
+
cd ../react-remote && npm install && npm run dev
|
|
10
|
+
|
|
11
|
+
# 2) 再启动本宿主(5314)
|
|
12
|
+
npm install
|
|
13
|
+
npm run dev # http://localhost:5314
|
|
14
|
+
npm run build # 产出 /bridge-vue-host/ 子路径产物
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## 关键点(对应 README §8.2)
|
|
18
|
+
|
|
19
|
+
- **双框架安装合同**:本宿主同时安装 `vue` + `react` + `react-dom`,shared 三键全部 `singleton: true`。
|
|
20
|
+
- **入口选择**:`@fulgurjs/federation/bridge/vue` 只携带 Vue 宿主适配器——dev 原生 ESM 与生产构建都不会加载 React 宿主适配代码(聚合入口 `/bridge` 会同时执行两者,仅兼容保留)。
|
|
21
|
+
- **`sessionKey`**:受控登录代次(非业务 props)。置 `null` = 登出态(立即卸载、不再请求);换账号走「null → `clearAppContext()` → 新代次」顺序,保证 A 的 context 字段零残留。
|
|
22
|
+
- **`getContext`**:同步纯 getter(`src/host-session.ts`),桥接层校验其快照的 `sessionKey` 后才代写 AppContext。
|
|
23
|
+
- **`appProps`**:挂载时浅拷贝快照;函数引用(`onReady`)保留原引用;换顶层引用不重挂,需要重置时用 `:key`。
|
|
24
|
+
- 错误占位默认内置中文诊断 +「重试加载 / 刷新页面重试」;可用 `errorComponent` 完全接管。
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { FederationOptions } from '@fulgurjs/federation'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Vue 桥接宿主联邦配置。
|
|
5
|
+
* 桥接模式使用合同(README §8.2 / 任务书 §3.5):宿主必须同时安装 vue + react + react-dom,
|
|
6
|
+
* 并把两套框架 shared 全部 singleton——缺 singleton 是使用违例(双实例症状见 README 故障表)。
|
|
7
|
+
* 推荐入口:/bridge/vue(只携带 Vue 宿主适配器,dev 与生产都不加载 React 宿主适配代码)。
|
|
8
|
+
*/
|
|
9
|
+
export default {
|
|
10
|
+
name: 'bridge-vue-host',
|
|
11
|
+
remotes: {
|
|
12
|
+
'bridge-react-remote': {
|
|
13
|
+
dev: 'http://localhost:5303',
|
|
14
|
+
prod: '/bridge-react-remote',
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
shared: {
|
|
18
|
+
vue: { singleton: true },
|
|
19
|
+
react: { singleton: true },
|
|
20
|
+
'react-dom': { singleton: true },
|
|
21
|
+
},
|
|
22
|
+
} satisfies FederationOptions
|