@lemon-fe/vite-plugin-micro-frontend 2.0.3 → 2.0.5

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
@@ -1,59 +1,26 @@
1
- import { Plugin, PluginOption } from 'vite';
2
- export { default as cssInjectedByJsPlugin } from 'vite-plugin-css-injected-by-js';
1
+ import { PluginOption } from 'vite';
3
2
  import { ModuleFederationOptions } from '@module-federation/vite';
4
3
 
5
- interface DevHmrPluginOptions {
6
- /** 入口文件路径,相对于项目根目录,默认为 src/main.tsx */
7
- entry?: string;
8
- }
9
- /** 旧的单独插件入口复用同一 HMR 实现,组合插件直接使用 federationRemoteHmrPlugin。 */
10
- declare function devHmrPlugin(options?: DevHmrPluginOptions): Plugin;
11
-
12
- /**
13
- * 生产构建动态 publicPath(类似 webpack `output.publicPath`)。
14
- * 依赖 [vite-plugin-dynamic-base](https://github.com/chenxch/vite-plugin-dynamic-base);
15
- * 生产环境请在应用的 `vite.config` 中使用占位 `base`,例如:
16
- * `base: process.env.NODE_ENV === "production" ? "/__dynamic_base__/" : "/"`。
17
- * 插件本身仅作用于 `vite build`(`apply: 'build'`),开发服务器不会启用。
18
- *
19
- * 推荐写法:只写「固定变量」取到的**动态域名**(`runtimeHostExpr`),应用路径与 Vite `base` 对齐(`appBase` 或与当前 `base` 一致)。
20
- */
4
+ /** 生产构建动态资源路径配置。 */
21
5
  type DynamicBaseConfig = {
22
- /** 传给 vite-plugin-dynamic-base,默认 true */
6
+ /** 改写生产构建生成的 HTML,默认 true。 */
23
7
  transformIndexHtml?: boolean;
24
8
  transformIndexHtmlConfig?: {
25
9
  insertBodyAfter?: boolean;
26
10
  publicPath?: string;
27
11
  };
28
- /**
29
- * 运行时代码表达式:求值为**域名或 origin 前缀**(不要包含应用 path),用于拼接真实 CDN/网关地址。
30
- * 变量名固定(如 `window.EARTH_BASE_CONFIG.EARTH_ALL_SHARE_HOST`),值为运行时动态域名。
31
- * 示例:`"(window.EARTH_BASE_CONFIG && window.EARTH_BASE_CONFIG.EARTH_ALL_SHARE_HOST ? window.EARTH_BASE_CONFIG.EARTH_ALL_SHARE_HOST.replace(/\\\\/$/, '') : '') + '/app-earth-wms'"`
32
- */
12
+ /** 返回完整资源前缀的运行时 JavaScript 表达式,可包含应用部署子路径。 */
33
13
  publicPath?: string;
34
- /**
35
- * 应用部署子路径(不含首尾 `/`),如 `app-earth-wms`。
36
- * 当生产 `base` 使用占位符 `/__dynamic_base__/` 时必填,用于 publicPath 拼接与 entry import 兜底改写。
37
- */
14
+ /** 应用部署子路径。默认从 Vite base 读取,使用 /__dynamic_base__/ 占位时可显式指定。 */
38
15
  appBase?: string;
39
- /**
40
- * 移除 HTML 中 `index-*.css` 的 link 与 dynamicBase 注入的对应 preload(样式全部由 JS 注入时使用)。
41
- */
16
+ /** 样式由应用自行注入时,移除入口 HTML 的 index-*.css link 和 preload。 */
42
17
  removeIndexCssPreload?: boolean;
43
18
  };
44
19
 
45
- interface DevelopmentShellConfig {
46
- /** 已部署支持 base/app 的基座地址。 */
47
- baseOrigin: string;
48
- remoteName?: string;
49
- }
50
-
51
20
  /**
52
21
  * 远程模块配置
53
22
  */
54
23
  interface RemoteConfig {
55
- /** 别名 */
56
- aliasName?: string;
57
24
  /** 远程模块名称 */
58
25
  remoteName: string;
59
26
  /** 入口文件路径 */
@@ -65,24 +32,12 @@ interface RemoteConfig {
65
32
  * 模块联邦配置
66
33
  */
67
34
  interface FederationApplicationConfig {
68
- /** 基座注册的应用名;默认从 microFrontendPlugins.appName 与 Vite base 推断 */
69
- appName?: string;
70
- /**
71
- * React 根组件入口。配置后生成带 AppRouter 的普通组件,独立启动入口不应包含在该模块中。
72
- */
73
- rootComponent?: string;
74
35
  /**
75
- * 已导出应用组件的入口,默认 src/main.tsx;不能与 rootComponent 同时配置。
36
+ * React 根组件入口,生成带 AppRouter 的普通组件。
76
37
  */
77
- entry?: string;
38
+ rootComponent: string;
78
39
  /** remote 仅构建联邦资源;默认保留 Vite 的 HTML 入口和显式 input 配置。 */
79
- buildMode?: 'remote' | 'html';
80
- /** 应用内部的挂载节点 id,默认使用 microFrontendPlugins 的 appName */
81
- mountElementId?: string;
82
- /** 能力文件名,默认为 micro-frontend.json */
83
- capabilityFileName?: string;
84
- /** 随能力文件发布的业务构建版本,可用于诊断和缓存追踪 */
85
- buildVersion?: string;
40
+ buildMode?: 'remote';
86
41
  }
87
42
  /** 官方 afterGenerate 回调接收的类型产物信息。 */
88
43
  interface FederationGeneratedTypes {
@@ -98,24 +53,17 @@ interface FederationDtsOptions extends Omit<OfficialDtsOptions, 'generateTypes'>
98
53
  afterGenerate?: (options: FederationGeneratedTypes) => Promise<void> | void;
99
54
  });
100
55
  }
101
- interface FederationConfig extends Omit<ModuleFederationOptions, 'name' | 'remotes' | 'exposes' | 'shared' | 'dts'> {
102
- /** 默认使用组合插件的 appName(连字符转下划线);单独调用 federationPlugin 时必填。 */
56
+ interface FederationConfig extends Omit<ModuleFederationOptions, 'name' | 'remotes' | 'exposes' | 'dts'> {
57
+ /** 默认使用 appName(连字符转下划线)。 */
103
58
  name?: string;
104
59
  /** 官方类型生成与消费配置,默认 true;可分别控制 generateTypes / consumeTypes。 */
105
60
  dts?: boolean | FederationDtsOptions;
106
61
  /** 暴露的模块 */
107
- shared?: ModuleFederationOptions['shared'];
108
62
  exposes?: NonNullable<ModuleFederationOptions['exposes']>;
109
- /**
110
- * exposes 目录路径,默认为 src/exposes
111
- * 插件会自动扫描该目录下的子目录作为暴露的模块
112
- * 例如:src/exposes/Button -> { './Button': './src/exposes/Button/index.tsx' }
113
- */
114
- exposesDir?: string;
63
+ /** 仅在 Vite 开发服务器中禁用 src/exposes 的自动暴露,默认 false。 */
64
+ disableAutoExposesInDev?: boolean;
115
65
  /** 远程模块配置 */
116
66
  remotes?: RemoteConfig[];
117
- /** 生成的文件路径,默认为 src/utils/mf.tsx */
118
- outputPath?: string;
119
67
  /**
120
68
  * 开发服务器地址,用于拼接远程模块入口
121
69
  * 例如:'http://localhost:5173'
@@ -123,14 +71,7 @@ interface FederationConfig extends Omit<ModuleFederationOptions, 'name' | 'remot
123
71
  */
124
72
  devHost?: string;
125
73
  /**
126
- * 开发态提供宿主 React 18 UMD 调试资源。宿主在启动前加载本地 development 构建,
127
- * 提前安装 Refresh hook,保持共享单例支持 Fast Refresh。
128
- * 默认 false;不改变生产构建,也不会自动替换已经加载的 React。
129
- */
130
- debugReactHost?: boolean;
131
- /**
132
- * 完整微应用的 React 组件配置。默认启用;设为 false 时只构建普通联邦模块,
133
- * 不生成 ./app 和 micro-frontend.json。
74
+ * 配有根组件时生成 ./app 和 micro-frontend.json。组件消费模式可设为 false。
134
75
  */
135
76
  application?: false | FederationApplicationConfig;
136
77
  }
@@ -147,27 +88,10 @@ interface RouteConfig {
147
88
  layout?: boolean;
148
89
  routes?: RouteConfig[];
149
90
  }
150
- /**
151
- * 组件元数据
152
- */
153
- interface ComponentMetadata {
154
- title?: string;
155
- keepAlive?: boolean;
156
- authority?: string[];
157
- }
158
91
  /**
159
92
  * 路由插件选项
160
93
  */
161
94
  interface RoutesPluginOptions {
162
- /** pages 目录路径,默认为 src/pages */
163
- pagesDir?: string;
164
- /** 生成的路由文件路径,默认为 src/routes.ts */
165
- outputPath?: string;
166
- /** 是否复用 Vite 文件监听自动更新路由,默认 true */
167
- watch?: boolean;
168
- /** 在内置工具目录之外追加忽略目录,默认 ['components', 'utils', 'hooks', 'typings'] */
169
- ignoreDirs?: string[];
170
- /** 自定义路由文件模板 */
171
95
  routeTemplate?: RoutesTemplateOptions;
172
96
  }
173
97
  /**
@@ -180,25 +104,19 @@ interface RoutesTemplateOptions {
180
104
  * 默认值为 @/components/loading, 项目中没有会报错
181
105
  */
182
106
  defaultLoadingComponentPath?: string;
183
- /** 国际化工具路径 */
184
- intlPath?: string;
185
- /** 页面别名前缀 */
186
- pageAliasPrefix?: string;
187
107
  }
188
108
  /**
189
109
  * mf 生成器选项
190
110
  */
191
111
  interface MfGeneratorOptions {
192
- /** 消费侧 Federation 实例名;组合插件自动传入 federation.name。省略时兼容默认实例。 */
193
- hostName?: string;
112
+ /** 消费侧 Federation 实例名。 */
113
+ hostName: string;
194
114
  /** 相对 remote entry 的源地址,与 federation.devHost 一致。 */
195
115
  devHost?: string;
196
116
  /** 与构建期 remote 注册保持相同的共享作用域。 */
197
117
  shareScope?: string | string[];
198
118
  /** 远程模块配置 */
199
119
  remotes: RemoteConfig[];
200
- /** 生成的文件路径,默认为 src/utils/mf.tsx */
201
- outputPath?: string;
202
120
  }
203
121
  /**
204
122
  * 微前端插件选项
@@ -206,97 +124,25 @@ interface MfGeneratorOptions {
206
124
  interface MicroFrontendPluginOptions {
207
125
  /** 应用名称 */
208
126
  appName: string;
209
- /** 本地入口启动已部署基座,仅 serve 生效。 */
210
- developmentShell?: DevelopmentShellConfig;
211
- /** @deprecated 未参与插件行为;开发模式由 Vite command 决定。 */
212
- useDevMode?: boolean;
127
+ /** 已部署基座的 HTTP(S) origin,仅本地开发生效。省略时不启动基座。 */
128
+ baseOrigin?: string;
213
129
  /** 模块联邦配置 */
214
130
  federation?: FederationConfig;
215
131
  /** 路由插件选项 */
216
132
  routes?: RoutesPluginOptions;
217
- /** @deprecated v2 默认使用 @module-federation/vite 的 remoteHmr,此选项不再参与组合插件。 */
218
- htmlTransform?: boolean | DevHmrPluginOptions;
219
- /** 生产构建启用动态资源路径;未配置则不注册 */
133
+ /** 生产构建的动态资源路径。 */
220
134
  dynamicBase?: DynamicBaseConfig | boolean;
221
135
  }
222
- type VitePlugin = Plugin;
223
136
 
224
137
  /**
225
138
  * 仅执行一次路由文件生成(供 CLI 或脚本调用,不依赖 Vite)
226
139
  */
227
- declare function generateRoutesToFile(options?: RoutesPluginOptions): Promise<void>;
228
- /**
229
- * 页面路由自动生成插件
230
- */
231
- declare function pagesRoutesPlugin(options?: RoutesPluginOptions): VitePlugin;
140
+ declare function generateRoutesToFile(options?: RoutesPluginOptions, root?: string): Promise<void>;
232
141
 
233
142
  /**
234
143
  * 仅执行一次 mf 文件生成(供 CLI 或脚本调用,不依赖 Vite)
235
144
  */
236
- declare function generateMf(options: MfGeneratorOptions): void;
237
- /**
238
- * mf.tsx 文件生成器插件
239
- * 根据配置的远程模块自动生成模块联邦工具文件
240
- */
241
- declare function mfGeneratorPlugin(options: MfGeneratorOptions): VitePlugin;
242
-
243
- interface FederationPluginContext {
244
- appName?: string;
245
- developmentShell?: boolean;
246
- }
247
- /**
248
- * 模块联邦插件
249
- * 整合了 federation 配置、exposes 自动扫描、remotes URL 构建等功能
250
- */
251
- declare function federationPlugin(federationOptions: FederationConfig, context?: FederationPluginContext): PluginOption[];
252
-
253
- /**
254
- * 生产构建专用:动态 publicPath(vite-plugin-dynamic-base + 可选 HTML 兜底)。
255
- * 仅 `vite build` 生效,与 {@link MicroFrontendPluginOptions.dynamicBase} 配合使用。
256
- */
257
- declare function getDynamicBasePlugins(options: DynamicBaseConfig | boolean): PluginOption[];
258
-
259
- type WithFalse<T> = {
260
- [P in keyof T]?: T[P] | false;
261
- };
262
-
263
- interface BaseIConfig {
264
- singular?: boolean;
265
- outputPath?: string;
266
- publicPath?: string;
267
- title?: string;
268
- mountElementId?: string;
269
- routes?: IRoute[];
270
- exportStatic?: {
271
- htmlSuffix?: boolean;
272
- dynamicRoot?: boolean;
273
- supportWin?: boolean;
274
- };
275
- }
276
-
277
- type IConfig = WithFalse<BaseIConfig>;
278
-
279
- interface IRoute {
280
- component?: any;
281
- exact?: boolean;
282
- path?: string;
283
- routes?: IRoute[];
284
- wrappers?: string[];
285
- title?: string;
286
- __toMerge?: boolean;
287
- __isDynamic?: boolean;
288
- [key: string]: any;
289
- }
290
-
291
- interface IOpts {
292
- root: string;
293
- relDir?: string;
294
- componentPrefix?: string;
295
- config: IConfig;
296
- ignoreDirs?: string[];
297
- excludedFiles?: string[];
298
- }
299
- declare function getRoutes(opts: IOpts): IRoute[];
145
+ declare function generateMf(options: MfGeneratorOptions, root?: string): void;
300
146
 
301
147
  /**
302
148
  * 微前端插件集合
@@ -307,5 +153,5 @@ declare function getRoutes(opts: IOpts): IRoute[];
307
153
  declare const MICRO_FRONTEND_OPTIONS_KEY = "__microFrontendOptions";
308
154
  declare function microFrontendPlugins(options: MicroFrontendPluginOptions): PluginOption[];
309
155
 
310
- export { MICRO_FRONTEND_OPTIONS_KEY, devHmrPlugin, federationPlugin, generateMf, generateRoutesToFile, getDynamicBasePlugins, getRoutes, mfGeneratorPlugin, microFrontendPlugins, pagesRoutesPlugin };
311
- export type { ComponentMetadata, DevelopmentShellConfig, DynamicBaseConfig, FederationApplicationConfig, FederationConfig, FederationDtsOptions, FederationGeneratedTypes, IRoute, MfGeneratorOptions, MicroFrontendPluginOptions, RemoteConfig, RouteConfig, RoutesPluginOptions, RoutesTemplateOptions, VitePlugin };
156
+ export { MICRO_FRONTEND_OPTIONS_KEY, generateMf, generateRoutesToFile, microFrontendPlugins };
157
+ export type { DynamicBaseConfig, FederationApplicationConfig, FederationConfig, FederationDtsOptions, FederationGeneratedTypes, MfGeneratorOptions, MicroFrontendPluginOptions, RemoteConfig, RouteConfig, RoutesPluginOptions, RoutesTemplateOptions };