@lemon-fe/vite-plugin-micro-frontend 2.0.0-beta.2 → 2.0.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/README.md +288 -139
- package/dist/cli.js +3 -2
- package/dist/index.d.ts +56 -59
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/runtime-app.d.ts +37 -0
- package/dist/runtime-app.js +82 -0
- package/dist/runtime-app.js.map +1 -0
- package/dist/runtime-dynamic.d.ts +2 -8
- package/dist/runtime-dynamic.js +7 -40
- package/dist/runtime-dynamic.js.map +1 -1
- package/dist/runtime-react-refresh-init.d.ts +1 -2
- package/dist/runtime-react-refresh-init.js +1 -169
- package/dist/runtime.d.ts +2 -2
- package/dist/runtime.js +2 -2
- package/package.json +11 -11
- package/dist/runtime-bridge.d.ts +0 -76
- package/dist/runtime-bridge.js +0 -185
- package/dist/runtime-bridge.js.map +0 -1
- package/dist/runtime-react-refresh-init.js.map +0 -1
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
|
|
55
|
+
/** 是否为 ES Module;true 使用 module,省略或 false 使用 var,不自动降级协议。 */
|
|
97
56
|
isESModule?: boolean;
|
|
98
57
|
}
|
|
99
58
|
/**
|
|
@@ -103,21 +62,27 @@ interface FederationApplicationConfig {
|
|
|
103
62
|
/** 基座注册的应用名;默认从 microFrontendPlugins.appName 与 Vite base 推断 */
|
|
104
63
|
appName?: string;
|
|
105
64
|
/**
|
|
106
|
-
* React
|
|
65
|
+
* React 根组件入口。配置后生成带 AppRouter 的普通组件,独立启动入口不应包含在该模块中。
|
|
107
66
|
*/
|
|
108
67
|
rootComponent?: string;
|
|
109
68
|
/**
|
|
110
|
-
*
|
|
69
|
+
* 已导出应用组件的入口,默认 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,20 +103,16 @@ interface FederationConfig extends Omit<ModuleFederationOptions, 'remotes' | 'ex
|
|
|
138
103
|
*/
|
|
139
104
|
devHost?: string;
|
|
140
105
|
/**
|
|
141
|
-
* 开发态提供宿主 React 18 UMD
|
|
142
|
-
*
|
|
106
|
+
* 开发态提供宿主 React 18 UMD 调试资源。宿主在启动前加载本地 development 构建,
|
|
107
|
+
* 提前安装 Refresh hook,保持共享单例支持 Fast Refresh。
|
|
143
108
|
* 默认 false;不改变生产构建,也不会自动替换已经加载的 React。
|
|
144
109
|
*/
|
|
145
110
|
debugReactHost?: boolean;
|
|
146
111
|
/**
|
|
147
|
-
* 完整微应用的 React
|
|
148
|
-
* 不生成 ./
|
|
112
|
+
* 完整微应用的 React 组件配置。默认启用;设为 false 时只构建普通联邦模块,
|
|
113
|
+
* 不生成 ./app 和 micro-frontend.json。
|
|
149
114
|
*/
|
|
150
115
|
application?: false | FederationApplicationConfig;
|
|
151
|
-
/** 官方 React Bridge Router 配置;默认启用并自动识别 React Router v5/v6/v7 */
|
|
152
|
-
bridge?: {
|
|
153
|
-
enableBridgeRouter?: boolean;
|
|
154
|
-
};
|
|
155
116
|
}
|
|
156
117
|
/**
|
|
157
118
|
* 路由配置
|
|
@@ -182,9 +143,9 @@ interface RoutesPluginOptions {
|
|
|
182
143
|
pagesDir?: string;
|
|
183
144
|
/** 生成的路由文件路径,默认为 src/routes.ts */
|
|
184
145
|
outputPath?: string;
|
|
185
|
-
/**
|
|
146
|
+
/** 是否复用 Vite 文件监听自动更新路由,默认 true */
|
|
186
147
|
watch?: boolean;
|
|
187
|
-
/**
|
|
148
|
+
/** 在内置工具目录之外追加忽略目录,默认 ['components', 'utils', 'hooks', 'typings'] */
|
|
188
149
|
ignoreDirs?: string[];
|
|
189
150
|
/** 自定义路由文件模板 */
|
|
190
151
|
routeTemplate?: RoutesTemplateOptions;
|
|
@@ -225,7 +186,7 @@ interface MfGeneratorOptions {
|
|
|
225
186
|
interface MicroFrontendPluginOptions {
|
|
226
187
|
/** 应用名称 */
|
|
227
188
|
appName: string;
|
|
228
|
-
/**
|
|
189
|
+
/** @deprecated 未参与插件行为;开发模式由 Vite command 决定。 */
|
|
229
190
|
useDevMode?: boolean;
|
|
230
191
|
/** 模块联邦配置 */
|
|
231
192
|
federation?: FederationConfig;
|
|
@@ -238,6 +199,40 @@ interface MicroFrontendPluginOptions {
|
|
|
238
199
|
}
|
|
239
200
|
type VitePlugin = Plugin;
|
|
240
201
|
|
|
202
|
+
/**
|
|
203
|
+
* 仅执行一次路由文件生成(供 CLI 或脚本调用,不依赖 Vite)
|
|
204
|
+
*/
|
|
205
|
+
declare function generateRoutesToFile(options?: RoutesPluginOptions): Promise<void>;
|
|
206
|
+
/**
|
|
207
|
+
* 页面路由自动生成插件
|
|
208
|
+
*/
|
|
209
|
+
declare function pagesRoutesPlugin(options?: RoutesPluginOptions): VitePlugin;
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* 仅执行一次 mf 文件生成(供 CLI 或脚本调用,不依赖 Vite)
|
|
213
|
+
*/
|
|
214
|
+
declare function generateMf(options: MfGeneratorOptions): void;
|
|
215
|
+
/**
|
|
216
|
+
* mf.tsx 文件生成器插件
|
|
217
|
+
* 根据配置的远程模块自动生成模块联邦工具文件
|
|
218
|
+
*/
|
|
219
|
+
declare function mfGeneratorPlugin(options: MfGeneratorOptions): VitePlugin;
|
|
220
|
+
|
|
221
|
+
interface FederationPluginContext {
|
|
222
|
+
appName?: string;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* 模块联邦插件
|
|
226
|
+
* 整合了 federation 配置、exposes 自动扫描、remotes URL 构建等功能
|
|
227
|
+
*/
|
|
228
|
+
declare function federationPlugin(federationOptions: FederationConfig, context?: FederationPluginContext): PluginOption[];
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* 生产构建专用:动态 publicPath(vite-plugin-dynamic-base + 可选 HTML 兜底)。
|
|
232
|
+
* 仅 `vite build` 生效,与 {@link MicroFrontendPluginOptions.dynamicBase} 配合使用。
|
|
233
|
+
*/
|
|
234
|
+
declare function getDynamicBasePlugins(options: DynamicBaseConfig | boolean): PluginOption[];
|
|
235
|
+
|
|
241
236
|
type WithFalse<T> = {
|
|
242
237
|
[P in keyof T]?: T[P] | false;
|
|
243
238
|
};
|
|
@@ -275,6 +270,8 @@ interface IOpts {
|
|
|
275
270
|
relDir?: string;
|
|
276
271
|
componentPrefix?: string;
|
|
277
272
|
config: IConfig;
|
|
273
|
+
ignoreDirs?: string[];
|
|
274
|
+
excludedFiles?: string[];
|
|
278
275
|
}
|
|
279
276
|
declare function getRoutes(opts: IOpts): IRoute[];
|
|
280
277
|
|
|
@@ -287,5 +284,5 @@ declare function getRoutes(opts: IOpts): IRoute[];
|
|
|
287
284
|
declare const MICRO_FRONTEND_OPTIONS_KEY = "__microFrontendOptions";
|
|
288
285
|
declare function microFrontendPlugins(options: MicroFrontendPluginOptions): PluginOption[];
|
|
289
286
|
|
|
290
|
-
export { MICRO_FRONTEND_OPTIONS_KEY,
|
|
287
|
+
export { MICRO_FRONTEND_OPTIONS_KEY, devHmrPlugin, federationPlugin, generateMf, generateRoutesToFile, getDynamicBasePlugins, getRoutes, mfGeneratorPlugin, microFrontendPlugins, pagesRoutesPlugin };
|
|
291
288
|
export type { ComponentMetadata, DynamicBaseConfig, FederationApplicationConfig, FederationConfig, IRoute, MfGeneratorOptions, MicroFrontendPluginOptions, RemoteConfig, RouteConfig, RoutesPluginOptions, RoutesTemplateOptions, VitePlugin };
|