@fulgurjs/federation 4.2.1 → 4.3.1

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.
@@ -141,17 +141,18 @@ onUnmounted(() => {
141
141
  |---|---|---|---|---|
142
142
  | 页面保活(多 tab 状态保留) | `keepAlive` | `boolean` | `false` | 页面数据条目(`src/fulgurjs/host/pages.data.ts`) |
143
143
  | 页面加载骨架屏 | —(内置,无配置项) | — | delay 200ms 的骨架占位 | 页面工厂内置(`pages.ts`) |
144
- | 空闲预载 | `PREFETCH_REMOTES`(宿主桥常量) | `string[]` | 全部 remotes 键 | `src/fulgurjs/host/bridge.ts` 顶部 |
144
+ | 空闲预载 | `PREFETCH_REMOTES`(宿主桥常量) | `string[]` | `[]`(关闭整远程预载,按需加载) | `src/fulgurjs/host/bridge.ts` 顶部 |
145
145
  | 联邦诊断面板 | —(内置页面) | — | 常驻 | 路由 `/fulgurjs-demo`(prod 为 `/main/fulgurjs-demo`) |
146
146
 
147
147
  ```ts
148
148
  // 保活:按页开启(默认全关——重型组件缓存成本高)
149
149
  { route: '/flowable/bpm/task/todo', name: 'BpmTodoTask', title: '待办任务', keepAlive: true }
150
150
 
151
- // 空闲预载三态(bridge.ts):
152
- const PREFETCH_REMOTES: string[] = ['mes-bpm', 'mes-lowcode'] // 默认:全部
153
- const PREFETCH_REMOTES: string[] = ['mes-bpm'] // 部分
154
- const PREFETCH_REMOTES: string[] = [] // 关闭
151
+ // 空闲预载三态(bridge.ts)——默认关闭整远程预载(按需加载;四层语义见 README §9.1.3):
152
+ const PREFETCH_REMOTES: string[] = [] // 默认:关闭(首访联邦页只下载该页所需)
153
+ const PREFETCH_REMOTES: string[] = ['mes-bpm'] // 显式预热整个远程(下载完整 expose 清单,不执行)
154
+ // 单页预取(推荐:只预取明确下一步页面,低优先级只下载不执行)
155
+ // idle(() => preloadRemote('mes-bpm/pages/bpm/task/todo', { mode: 'prefetch' }))
155
156
  ```
156
157
 
157
158
  边界:保活缓存上限 max=8(LRU);骨架屏 delay 200ms 防闪、失败走内置错误占位(错误码+根因+修法);预载失败 MFU-007(fulgurjs:error 事件,不阻断业务);保活页的 window 级监听/定时器按「三D 清理清单」处理。
@@ -0,0 +1,22 @@
1
+ # examples — 可复制的单项目配置样例
2
+
3
+ 每个目录是一个**独立项目**的 `fulgurjs.config.ts`(4.2.0 单项目契约:默认导出直接可传给 `federation()`):
4
+
5
+ - [`remote-a/fulgurjs.config.ts`](./remote-a/fulgurjs.config.ts) — 远程应用:exposes / setup / shared
6
+ - [`host/fulgurjs.config.ts`](./host/fulgurjs.config.ts) — 宿主应用:remotes 消费地址 + 可选 `hostPages` 页面核对数据(仅供 CLI)
7
+
8
+ 复制方式:把对应文件整份复制到**你自己的项目根目录**(两个项目不共享配置文件、不共享父目录配置),再在各自 `vite.config.ts` 的 plugins 里加一次 `federation(fulgurjsConfig)`:
9
+
10
+ ```ts
11
+ import federation from '@fulgurjs/federation'
12
+ import fulgurjsConfig from './fulgurjs.config'
13
+
14
+ export default defineConfig({
15
+ plugins: [
16
+ // ...原有插件,
17
+ federation(fulgurjsConfig),
18
+ ],
19
+ })
20
+ ```
21
+
22
+ 验证:在复制后的项目根目录运行 `npx fulgurjs explain`(纯本地、无网络),应输出本应用的形态摘要与 `federation(fulgurjsConfig)` 接入块。
@@ -0,0 +1,26 @@
1
+ // host/fulgurjs.config.ts —— 宿主应用自己的配置(一项目一份;整文件可复制到你的宿主项目根目录)
2
+ //
3
+ // 宿主只写自己的 name / remotes / shared;页面核对数据以具名导出 hostPages 提供给 CLI。
4
+ // Vite 接入(本项目 vite.config.ts 只需两行联邦相关代码):
5
+ // import federation from '@fulgurjs/federation'
6
+ // import fulgurjsConfig from './fulgurjs.config'
7
+ // // plugins: [ ...原有插件, federation(fulgurjsConfig) ]
8
+ import type { FederationOptions } from '@fulgurjs/federation'
9
+
10
+ export default {
11
+ name: 'host-app',
12
+ // 消费的远程(键 = import 前缀;dev/prod 地址二段式,单地址字符串也行)
13
+ remotes: {
14
+ 'remote-a': { dev: 'http://localhost:5174/remote-a', prod: '/remote-a' },
15
+ },
16
+ shared: {
17
+ vue: { singleton: true },
18
+ },
19
+ } satisfies FederationOptions
20
+
21
+ // ── 以下仅供 CLI explain/check-pages 读取(不是 federation() 的参数)──
22
+ // 页面数据与运行时 createHostPages 消费同一份纯数据模块(唯一手工维护位置)
23
+ export const hostPages = {
24
+ remotePrefixes: { '/remote-a/': 'remote-a' },
25
+ pages: [{ route: '/remote-a/home', name: 'RemoteAHome', title: '首页' }],
26
+ }
@@ -0,0 +1,24 @@
1
+ // remote-a/fulgurjs.config.ts —— 远程应用自己的配置(一项目一份;整文件可复制到你的远程项目根目录)
2
+ //
3
+ // Vite 接入(本项目 vite.config.ts 只需两行联邦相关代码):
4
+ // import federation from '@fulgurjs/federation'
5
+ // import fulgurjsConfig from './fulgurjs.config'
6
+ // // plugins: [ ...原有插件, federation(fulgurjsConfig) ]
7
+ //
8
+ // CLI(纯本地,无网络):npx fulgurjs explain
9
+ import type { FederationOptions } from '@fulgurjs/federation'
10
+
11
+ export default {
12
+ // 联邦容器名(宿主引用它时用这个名;同一页面内唯一)
13
+ name: 'remote-a',
14
+ // 对外暴露的模块:'./键' → 相对本项目根的源文件路径
15
+ exposes: {
16
+ './pages/remote-a/home': './src/views/Home.vue',
17
+ './pages/remote-a/detail': './src/views/Detail.vue',
18
+ },
19
+ // 可选:远程需要启动期初始化(全局样式/组件/locale)时声明入口文件
20
+ // setup: './src/fulgurjs/setup.ts',
21
+ shared: {
22
+ vue: { singleton: true },
23
+ },
24
+ } satisfies FederationOptions
@@ -0,0 +1,3 @@
1
+ <template>
2
+ <div>remote-a detail</div>
3
+ </template>
@@ -0,0 +1,3 @@
1
+ <template>
2
+ <div>remote-a home</div>
3
+ </template>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fulgurjs/federation",
3
- "version": "4.2.1",
3
+ "version": "4.3.1",
4
4
  "type": "module",
5
5
  "description": "Vite Module Federation with full Webpack MF parity. Dev & production, no compromise.",
6
6
  "license": "MIT",
@@ -75,6 +75,7 @@
75
75
  },
76
76
  "dependencies": {
77
77
  "es-module-lexer": "^1.6.0",
78
+ "esbuild": "^0.27.0",
78
79
  "magic-string": "^0.30.17"
79
80
  },
80
81
  "devDependencies": {
@@ -1,33 +0,0 @@
1
- /**
2
- * 通用起步样例(4.2.0 单项目契约形态):一个远程 + 一个宿主各一份配置。
3
- * 完整字段说明见 `fulgurjs init` 生成的起步模板(fulgurjs init --template fulgurjs.config.ts)。
4
- */
5
- import type { FederationOptions } from '@fulgurjs/federation'
6
-
7
- // ── remote-a/fulgurjs.config.ts(远程应用自己的配置)──
8
- export const remoteAConfig = {
9
- name: 'remote-a',
10
- exposes: {
11
- './pages/remote-a/home': './src/views/Home.vue',
12
- './pages/remote-a/detail': './src/views/Detail.vue',
13
- },
14
- shared: { vue: { singleton: true } },
15
- } satisfies FederationOptions
16
-
17
- // ── host/fulgurjs.config.ts(宿主应用自己的配置:消费地址 + 可选页面核对数据)──
18
- export const hostConfig = {
19
- name: 'host-app',
20
- remotes: {
21
- 'remote-a': { dev: 'http://localhost:5174/remote-a', prod: '/remote-a' },
22
- },
23
- shared: { vue: { singleton: true } },
24
- } satisfies FederationOptions
25
-
26
- // 宿主页面核对数据(具名导出 hostPages,仅供 CLI explain/check-pages;不是 federation() 参数):
27
- // export const hostPages = { pages: [{ route: '/remote-a/home', name: 'RemoteAHome', title: '首页' }],
28
- // remotePrefixes: { '/remote-a/': 'remote-a' } }
29
-
30
- // 各自 vite.config.ts 里:
31
- // import federation from '@fulgurjs/federation'
32
- // import fulgurjsConfig from './fulgurjs.config'
33
- // plugins: [ ..., federation(fulgurjsConfig) ]