@lemon-fe/vite-plugin-micro-frontend 1.1.3 → 1.1.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,7 +1,37 @@
1
1
  import { Plugin, PluginOption } from 'vite';
2
2
  export { default as cssInjectedByJsPlugin } from 'vite-plugin-css-injected-by-js';
3
- import { VitePluginFederationOptions } from '@originjs/vite-plugin-federation';
4
- 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;
5
35
 
6
36
  /**
7
37
  * 远程模块配置
@@ -19,11 +49,10 @@ interface RemoteConfig {
19
49
  /**
20
50
  * 模块联邦配置
21
51
  */
22
- interface FederationConfig extends Omit<VitePluginFederationOptions, "remotes"> {
23
- /** 应用名称 */
24
- name: string;
25
- /** 远程入口文件名 */
26
- filename?: string;
52
+ interface FederationConfig extends Omit<ModuleFederationOptions, "remotes"> {
53
+ /** 暴露的模块 */
54
+ shared?: Record<string, string>;
55
+ exposes?: Record<string, string>;
27
56
  /**
28
57
  * exposes 目录路径,默认为 src/exposes
29
58
  * 插件会自动扫描该目录下的子目录作为暴露的模块
@@ -114,7 +143,7 @@ interface MicroFrontendPluginOptions {
114
143
  /** 路由插件选项 */
115
144
  routes?: RoutesPluginOptions;
116
145
  /** 是否启用 HTML 转换(移除 refresh 脚本) */
117
- htmlTransform?: boolean;
146
+ htmlTransform?: boolean | DevHmrPluginOptions;
118
147
  /** qiankun 配置 */
119
148
  qiankun?: {
120
149
  /** 是否启用 qiankun */
@@ -125,45 +154,6 @@ interface MicroFrontendPluginOptions {
125
154
  }
126
155
  type VitePlugin = Plugin;
127
156
 
128
- /**
129
- * HTML 转换插件 - 开发环境下处理 React Refresh 脚本
130
- * 在乾坤微前端场景下,需要替换默认的 refresh 脚本以支持沙箱环境
131
- * 只在开发环境(vite dev)下生效,生产环境不做任何处理
132
- */
133
- declare function htmlRemoveFreshPlugin(): VitePlugin;
134
-
135
- /**
136
- * 页面路由自动生成插件
137
- */
138
- declare function pagesRoutesPlugin(options?: RoutesPluginOptions): VitePlugin;
139
-
140
- /**
141
- * mf.tsx 文件生成器插件
142
- * 根据配置的远程模块自动生成模块联邦工具文件
143
- */
144
- declare function mfGeneratorPlugin(options: MfGeneratorOptions): VitePlugin;
145
-
146
- /**
147
- * 模块联邦插件
148
- * 整合了 federation 配置、exposes 自动扫描、remotes URL 构建等功能
149
- */
150
- declare function federationPlugin(federationOptions: FederationConfig): PluginOption[];
151
-
152
- declare function autoExternalAntd(): Plugin;
153
-
154
- interface DynamicOptions<P = Record<string, unknown>> {
155
- /** 动态加载函数,返回一个包含 default 导出的 Promise */
156
- loader: () => Promise<{
157
- default: ComponentType<P>;
158
- }>;
159
- /** 加载中/加载失败时显示的组件 */
160
- loading?: ComponentType<any>;
161
- }
162
- /**
163
- * 封装动态导入函数,兼容 Umi 的 dynamic
164
- */
165
- declare function dynamic<P = Record<string, unknown>>(options: DynamicOptions<P>): ComponentType<P>;
166
-
167
157
  type WithFalse<T> = {
168
158
  [P in keyof T]?: T[P] | false;
169
159
  };
@@ -211,5 +201,5 @@ declare function getRoutes(opts: IOpts): IRoute[];
211
201
  */
212
202
  declare function microFrontendPlugins(options: MicroFrontendPluginOptions): PluginOption[];
213
203
 
214
- export { autoExternalAntd, dynamic, federationPlugin, getRoutes, htmlRemoveFreshPlugin, mfGeneratorPlugin, microFrontendPlugins, pagesRoutesPlugin };
215
- 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 };