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