@lemon-fe/vite-plugin-micro-frontend 2.0.0-beta.2 → 2.0.0-beta.3

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/dist/index.d.ts CHANGED
@@ -6,42 +6,9 @@ interface DevHmrPluginOptions {
6
6
  /** 入口文件路径,相对于项目根目录,默认为 src/main.tsx */
7
7
  entry?: string;
8
8
  }
9
- /**
10
- * 微前端开发环境 HMR 插件(合并版)
11
- * 1. HTML 转换:移除默认 refresh preamble,由远程应用自己的 origin 初始化
12
- * 2. 入口注入:在入口最顶部自动注入 react-refresh-init,接管远程模块的 HMR 监听
13
- * 仅开发环境生效。v2 组合插件默认使用官方 remoteHmr;如需旧协议,必须单独注册此插件。
14
- */
9
+ /** 旧的单独插件入口复用同一 HMR 实现,组合插件直接使用 federationRemoteHmrPlugin。 */
15
10
  declare function devHmrPlugin(options?: DevHmrPluginOptions): Plugin;
16
11
 
17
- /**
18
- * 仅执行一次路由文件生成(供 CLI 或脚本调用,不依赖 Vite)
19
- */
20
- declare function generateRoutesToFile(options?: RoutesPluginOptions): Promise<void>;
21
- /**
22
- * 页面路由自动生成插件
23
- */
24
- declare function pagesRoutesPlugin(options?: RoutesPluginOptions): VitePlugin;
25
-
26
- /**
27
- * 仅执行一次 mf 文件生成(供 CLI 或脚本调用,不依赖 Vite)
28
- */
29
- declare function generateMf(options: MfGeneratorOptions): void;
30
- /**
31
- * mf.tsx 文件生成器插件
32
- * 根据配置的远程模块自动生成模块联邦工具文件
33
- */
34
- declare function mfGeneratorPlugin(options: MfGeneratorOptions): VitePlugin;
35
-
36
- interface FederationPluginContext {
37
- appName?: string;
38
- }
39
- /**
40
- * 模块联邦插件
41
- * 整合了 federation 配置、exposes 自动扫描、remotes URL 构建等功能
42
- */
43
- declare function federationPlugin(federationOptions: FederationConfig, context?: FederationPluginContext): PluginOption[];
44
-
45
12
  /**
46
13
  * 生产构建动态 publicPath(类似 webpack `output.publicPath`)。
47
14
  * 依赖 [vite-plugin-dynamic-base](https://github.com/chenxch/vite-plugin-dynamic-base);
@@ -75,14 +42,6 @@ type DynamicBaseConfig = {
75
42
  removeIndexCssPreload?: boolean;
76
43
  };
77
44
 
78
- /**
79
- * 生产构建专用:动态 publicPath(vite-plugin-dynamic-base + 可选 HTML 兜底)。
80
- * 仅 `vite build` 生效,与 {@link MicroFrontendPluginOptions.dynamicBase} 配合使用。
81
- */
82
- declare function getDynamicBasePlugins(options: DynamicBaseConfig | boolean): PluginOption[];
83
-
84
- declare function autoExternalAntd(): Plugin;
85
-
86
45
  /**
87
46
  * 远程模块配置
88
47
  */
@@ -93,7 +52,7 @@ interface RemoteConfig {
93
52
  remoteName: string;
94
53
  /** 入口文件路径 */
95
54
  entry: string;
96
- /** 是否为 ES Module;为 true 时优先 dynamic import,失败则自动降级为 UMD script 加载 */
55
+ /** 是否为 ES Module;true 使用 module,省略或 false 使用 var,不自动降级协议。 */
97
56
  isESModule?: boolean;
98
57
  }
99
58
  /**
@@ -107,17 +66,23 @@ interface FederationApplicationConfig {
107
66
  */
108
67
  rootComponent?: string;
109
68
  /**
110
- * 兼容旧项目的生命周期入口,默认 src/main.tsx;不能与 rootComponent 同时配置。
69
+ * 已导出 Bridge provider 的入口,默认 src/main.tsx;不能与 rootComponent 同时配置。
111
70
  */
112
71
  entry?: string;
72
+ /** remote 仅构建联邦资源;默认保留 Vite 的 HTML 入口和显式 input 配置。 */
73
+ buildMode?: 'remote' | 'html';
113
74
  /** 应用内部的挂载节点 id,默认使用 microFrontendPlugins 的 appName */
114
75
  mountElementId?: string;
115
76
  /** 能力文件名,默认为 micro-frontend.json */
116
77
  capabilityFileName?: string;
117
- /** 每次发布唯一的构建版本;生产构建未提供时自动生成,开发态不自动生成。 */
78
+ /** 随能力文件发布的业务构建版本,可用于诊断和缓存追踪 */
118
79
  buildVersion?: string;
119
80
  }
120
- interface FederationConfig extends Omit<ModuleFederationOptions, 'remotes' | 'exposes' | 'shared'> {
81
+ interface FederationConfig extends Omit<ModuleFederationOptions, 'name' | 'remotes' | 'exposes' | 'shared'> {
82
+ /** 默认使用组合插件的 appName(连字符转下划线);单独调用 federationPlugin 时必填。 */
83
+ name?: string;
84
+ /** 官方类型生成与消费配置,默认 true;可分别控制 generateTypes / consumeTypes。 */
85
+ dts?: ModuleFederationOptions['dts'];
121
86
  /** 暴露的模块 */
122
87
  shared?: ModuleFederationOptions['shared'];
123
88
  exposes?: NonNullable<ModuleFederationOptions['exposes']>;
@@ -138,17 +103,17 @@ interface FederationConfig extends Omit<ModuleFederationOptions, 'remotes' | 'ex
138
103
  */
139
104
  devHost?: string;
140
105
  /**
141
- * 开发态提供宿主 React 18 UMD 调试资源。通过浏览器代理将宿主 React/ReactDOM CDN
142
- * 请求替换为本地 development 构建并提前安装 Refresh hook,保持共享单例支持 Fast Refresh。
106
+ * 开发态提供宿主 React 18 UMD 调试资源。宿主在启动前加载本地 development 构建,
107
+ * 提前安装 Refresh hook,保持共享单例支持 Fast Refresh。
143
108
  * 默认 false;不改变生产构建,也不会自动替换已经加载的 React。
144
109
  */
145
110
  debugReactHost?: boolean;
146
111
  /**
147
112
  * 完整微应用的 React Bridge 配置。默认启用;设为 false 时只构建普通联邦模块,
148
- * 不生成 ./export-app 和 micro-frontend.json。
113
+ * 不生成 ./app 和 micro-frontend.json。
149
114
  */
150
115
  application?: false | FederationApplicationConfig;
151
- /** 官方 React Bridge Router 配置;默认启用并自动识别 React Router v5/v6/v7 */
116
+ /** 官方 React Bridge Router 配置;默认关闭,只有显式设为 true 时启用 */
152
117
  bridge?: {
153
118
  enableBridgeRouter?: boolean;
154
119
  };
@@ -182,9 +147,9 @@ interface RoutesPluginOptions {
182
147
  pagesDir?: string;
183
148
  /** 生成的路由文件路径,默认为 src/routes.ts */
184
149
  outputPath?: string;
185
- /** 是否启用文件监听 */
150
+ /** 是否复用 Vite 文件监听自动更新路由,默认 true */
186
151
  watch?: boolean;
187
- /** 忽略的目录 */
152
+ /** 在内置工具目录之外追加忽略目录,默认 ['components', 'utils', 'hooks', 'typings'] */
188
153
  ignoreDirs?: string[];
189
154
  /** 自定义路由文件模板 */
190
155
  routeTemplate?: RoutesTemplateOptions;
@@ -225,7 +190,7 @@ interface MfGeneratorOptions {
225
190
  interface MicroFrontendPluginOptions {
226
191
  /** 应用名称 */
227
192
  appName: string;
228
- /** 是否为开发模式 */
193
+ /** @deprecated 未参与插件行为;开发模式由 Vite command 决定。 */
229
194
  useDevMode?: boolean;
230
195
  /** 模块联邦配置 */
231
196
  federation?: FederationConfig;
@@ -238,6 +203,40 @@ interface MicroFrontendPluginOptions {
238
203
  }
239
204
  type VitePlugin = Plugin;
240
205
 
206
+ /**
207
+ * 仅执行一次路由文件生成(供 CLI 或脚本调用,不依赖 Vite)
208
+ */
209
+ declare function generateRoutesToFile(options?: RoutesPluginOptions): Promise<void>;
210
+ /**
211
+ * 页面路由自动生成插件
212
+ */
213
+ declare function pagesRoutesPlugin(options?: RoutesPluginOptions): VitePlugin;
214
+
215
+ /**
216
+ * 仅执行一次 mf 文件生成(供 CLI 或脚本调用,不依赖 Vite)
217
+ */
218
+ declare function generateMf(options: MfGeneratorOptions): void;
219
+ /**
220
+ * mf.tsx 文件生成器插件
221
+ * 根据配置的远程模块自动生成模块联邦工具文件
222
+ */
223
+ declare function mfGeneratorPlugin(options: MfGeneratorOptions): VitePlugin;
224
+
225
+ interface FederationPluginContext {
226
+ appName?: string;
227
+ }
228
+ /**
229
+ * 模块联邦插件
230
+ * 整合了 federation 配置、exposes 自动扫描、remotes URL 构建等功能
231
+ */
232
+ declare function federationPlugin(federationOptions: FederationConfig, context?: FederationPluginContext): PluginOption[];
233
+
234
+ /**
235
+ * 生产构建专用:动态 publicPath(vite-plugin-dynamic-base + 可选 HTML 兜底)。
236
+ * 仅 `vite build` 生效,与 {@link MicroFrontendPluginOptions.dynamicBase} 配合使用。
237
+ */
238
+ declare function getDynamicBasePlugins(options: DynamicBaseConfig | boolean): PluginOption[];
239
+
241
240
  type WithFalse<T> = {
242
241
  [P in keyof T]?: T[P] | false;
243
242
  };
@@ -275,6 +274,8 @@ interface IOpts {
275
274
  relDir?: string;
276
275
  componentPrefix?: string;
277
276
  config: IConfig;
277
+ ignoreDirs?: string[];
278
+ excludedFiles?: string[];
278
279
  }
279
280
  declare function getRoutes(opts: IOpts): IRoute[];
280
281
 
@@ -287,5 +288,5 @@ declare function getRoutes(opts: IOpts): IRoute[];
287
288
  declare const MICRO_FRONTEND_OPTIONS_KEY = "__microFrontendOptions";
288
289
  declare function microFrontendPlugins(options: MicroFrontendPluginOptions): PluginOption[];
289
290
 
290
- export { MICRO_FRONTEND_OPTIONS_KEY, autoExternalAntd, devHmrPlugin, federationPlugin, generateMf, generateRoutesToFile, getDynamicBasePlugins, getRoutes, mfGeneratorPlugin, microFrontendPlugins, pagesRoutesPlugin };
291
+ export { MICRO_FRONTEND_OPTIONS_KEY, devHmrPlugin, federationPlugin, generateMf, generateRoutesToFile, getDynamicBasePlugins, getRoutes, mfGeneratorPlugin, microFrontendPlugins, pagesRoutesPlugin };
291
292
  export type { ComponentMetadata, DynamicBaseConfig, FederationApplicationConfig, FederationConfig, IRoute, MfGeneratorOptions, MicroFrontendPluginOptions, RemoteConfig, RouteConfig, RoutesPluginOptions, RoutesTemplateOptions, VitePlugin };