@lemon-fe/vite-plugin-micro-frontend 1.1.4 → 1.1.7

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,6 +1,37 @@
1
1
  import { Plugin, PluginOption } from 'vite';
2
2
  export { default as cssInjectedByJsPlugin } from 'vite-plugin-css-injected-by-js';
3
- import { ComponentType } from 'react';
3
+ import { ModuleFederationOptions } from '@module-federation/vite/lib/utils/normalizeModuleFederationOptions';
4
+
5
+ interface DevHmrPluginOptions {
6
+ /** 入口文件路径,相对于项目根目录,默认为 src/main.tsx */
7
+ entry?: string;
8
+ }
9
+ /**
10
+ * 微前端开发环境 HMR 插件(合并版)
11
+ * 1. HTML 转换:仅移除 @vitejs/plugin-react 注入的默认 refresh 脚本,避免乾坤下路径错误和控制台报错(不在此注入替换脚本)
12
+ * 2. 入口注入:在入口最顶部自动注入 react-refresh-init,由它统一负责 preamble、@react-refresh 加载、proxy 注入和 HMR 监听
13
+ * 仅开发环境生效,通过 microFrontendPlugins 的 htmlTransform 配置项启用,无需在 vite.config 中显式添加
14
+ */
15
+ declare function devHmrPlugin(options?: DevHmrPluginOptions): Plugin;
16
+
17
+ /**
18
+ * 页面路由自动生成插件
19
+ */
20
+ declare function pagesRoutesPlugin(options?: RoutesPluginOptions): VitePlugin;
21
+
22
+ /**
23
+ * mf.tsx 文件生成器插件
24
+ * 根据配置的远程模块自动生成模块联邦工具文件
25
+ */
26
+ declare function mfGeneratorPlugin(options: MfGeneratorOptions): VitePlugin;
27
+
28
+ /**
29
+ * 模块联邦插件
30
+ * 整合了 federation 配置、exposes 自动扫描、remotes URL 构建等功能
31
+ */
32
+ declare function federationPlugin(federationOptions: FederationConfig): PluginOption[];
33
+
34
+ declare function autoExternalAntd(): Plugin;
4
35
 
5
36
  /**
6
37
  * 远程模块配置
@@ -18,11 +49,7 @@ interface RemoteConfig {
18
49
  /**
19
50
  * 模块联邦配置
20
51
  */
21
- interface FederationConfig {
22
- /** 应用名称 */
23
- name: string;
24
- /** 远程入口文件名 */
25
- filename?: string;
52
+ interface FederationConfig extends Omit<ModuleFederationOptions, "remotes"> {
26
53
  /** 暴露的模块 */
27
54
  shared?: Record<string, string>;
28
55
  exposes?: Record<string, string>;
@@ -116,7 +143,7 @@ interface MicroFrontendPluginOptions {
116
143
  /** 路由插件选项 */
117
144
  routes?: RoutesPluginOptions;
118
145
  /** 是否启用 HTML 转换(移除 refresh 脚本) */
119
- htmlTransform?: boolean;
146
+ htmlTransform?: boolean | DevHmrPluginOptions;
120
147
  /** qiankun 配置 */
121
148
  qiankun?: {
122
149
  /** 是否启用 qiankun */
@@ -127,45 +154,6 @@ interface MicroFrontendPluginOptions {
127
154
  }
128
155
  type VitePlugin = Plugin;
129
156
 
130
- /**
131
- * HTML 转换插件 - 开发环境下处理 React Refresh 脚本
132
- * 在乾坤微前端场景下,需要替换默认的 refresh 脚本以支持沙箱环境
133
- * 只在开发环境(vite dev)下生效,生产环境不做任何处理
134
- */
135
- declare function htmlRemoveFreshPlugin(): VitePlugin;
136
-
137
- /**
138
- * 页面路由自动生成插件
139
- */
140
- declare function pagesRoutesPlugin(options?: RoutesPluginOptions): VitePlugin;
141
-
142
- /**
143
- * mf.tsx 文件生成器插件
144
- * 根据配置的远程模块自动生成模块联邦工具文件
145
- */
146
- declare function mfGeneratorPlugin(options: MfGeneratorOptions): VitePlugin;
147
-
148
- /**
149
- * 模块联邦插件
150
- * 整合了 federation 配置、exposes 自动扫描、remotes URL 构建等功能
151
- */
152
- declare function federationPlugin(federationOptions: FederationConfig): PluginOption[];
153
-
154
- declare function autoExternalAntd(): Plugin;
155
-
156
- interface DynamicOptions<P = Record<string, unknown>> {
157
- /** 动态加载函数,返回一个包含 default 导出的 Promise */
158
- loader: () => Promise<{
159
- default: ComponentType<P>;
160
- }>;
161
- /** 加载中/加载失败时显示的组件 */
162
- loading?: ComponentType<any>;
163
- }
164
- /**
165
- * 封装动态导入函数,兼容 Umi 的 dynamic
166
- */
167
- declare function dynamic<P = Record<string, unknown>>(options: DynamicOptions<P>): ComponentType<P>;
168
-
169
157
  type WithFalse<T> = {
170
158
  [P in keyof T]?: T[P] | false;
171
159
  };
@@ -213,5 +201,5 @@ declare function getRoutes(opts: IOpts): IRoute[];
213
201
  */
214
202
  declare function microFrontendPlugins(options: MicroFrontendPluginOptions): PluginOption[];
215
203
 
216
- export { autoExternalAntd, dynamic, federationPlugin, getRoutes, htmlRemoveFreshPlugin, mfGeneratorPlugin, microFrontendPlugins, pagesRoutesPlugin };
217
- export type { ComponentMetadata, DynamicOptions, FederationConfig, IRoute, MfGeneratorOptions, MicroFrontendPluginOptions, RemoteConfig, RouteConfig, RoutesPluginOptions, RoutesTemplateOptions, VitePlugin };
204
+ export { autoExternalAntd, devHmrPlugin, federationPlugin, getRoutes, mfGeneratorPlugin, microFrontendPlugins, pagesRoutesPlugin };
205
+ export type { ComponentMetadata, FederationConfig, IRoute, MfGeneratorOptions, MicroFrontendPluginOptions, RemoteConfig, RouteConfig, RoutesPluginOptions, RoutesTemplateOptions, VitePlugin };