@lemon-fe/vite-plugin-micro-frontend 1.0.3 → 1.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
@@ -20,14 +20,29 @@ interface FederationConfig {
20
20
  name: string;
21
21
  /** 远程入口文件名 */
22
22
  filename?: string;
23
- /** 暴露的模块 */
23
+ /**
24
+ * 暴露的模块(手动配置)
25
+ * 会与自动扫描的 exposes 合并,手动配置优先级更高
26
+ */
24
27
  exposes?: Record<string, string>;
28
+ /**
29
+ * exposes 目录路径,默认为 src/exposes
30
+ * 插件会自动扫描该目录下的子目录作为暴露的模块
31
+ * 例如:src/exposes/Button -> { './Button': './src/exposes/Button/index.tsx' }
32
+ */
33
+ exposesDir?: string;
25
34
  /** 远程模块配置 */
26
- remotes?: Record<string, RemoteConfig>;
35
+ remotes?: RemoteConfig[];
27
36
  /** 共享依赖 */
28
37
  shared?: string[];
29
38
  /** 生成的文件路径,默认为 src/utils/mf.tsx */
30
39
  outputPath?: string;
40
+ /**
41
+ * 开发服务器地址,用于拼接远程模块入口
42
+ * 例如:'http://localhost:5173'
43
+ * 如果不设置,将使用 remotes 中的 entry 作为完整 URL
44
+ */
45
+ devHost?: string;
31
46
  }
32
47
  /**
33
48
  * 路由配置
@@ -85,7 +100,7 @@ interface RoutesTemplateOptions {
85
100
  */
86
101
  interface MfGeneratorOptions {
87
102
  /** 远程模块配置 */
88
- remotes: Record<string, RemoteConfig>;
103
+ remotes: RemoteConfig[];
89
104
  /** 生成的文件路径,默认为 src/utils/mf.tsx */
90
105
  outputPath?: string;
91
106
  }
@@ -130,6 +145,12 @@ declare function pagesRoutesPlugin(options?: RoutesPluginOptions): VitePlugin;
130
145
  */
131
146
  declare function mfGeneratorPlugin(options: MfGeneratorOptions): VitePlugin;
132
147
 
148
+ /**
149
+ * 模块联邦插件
150
+ * 整合了 federation 配置、exposes 自动扫描、remotes URL 构建等功能
151
+ */
152
+ declare function federationPlugin(federationOptions: FederationConfig): PluginOption[];
153
+
133
154
  interface DynamicOptions<P = Record<string, unknown>> {
134
155
  /** 动态加载函数,返回一个包含 default 导出的 Promise */
135
156
  loader: () => Promise<{
@@ -158,69 +179,52 @@ interface DynamicOptions<P = Record<string, unknown>> {
158
179
  */
159
180
  declare function dynamic<P = Record<string, unknown>>(options: DynamicOptions<P>): ComponentType<P>;
160
181
 
182
+ type WithFalse<T> = {
183
+ [P in keyof T]?: T[P] | false;
184
+ };
185
+
186
+ interface BaseIConfig {
187
+ singular?: boolean;
188
+ outputPath?: string;
189
+ publicPath?: string;
190
+ title?: string;
191
+ mountElementId?: string;
192
+ routes?: IRoute[];
193
+ exportStatic?: {
194
+ htmlSuffix?: boolean;
195
+ dynamicRoot?: boolean;
196
+ supportWin?: boolean;
197
+ };
198
+ }
199
+
200
+ type IConfig = WithFalse<BaseIConfig>;
201
+
202
+ interface IRoute {
203
+ component?: any;
204
+ exact?: boolean;
205
+ path?: string;
206
+ routes?: IRoute[];
207
+ wrappers?: string[];
208
+ title?: string;
209
+ __toMerge?: boolean;
210
+ __isDynamic?: boolean;
211
+ [key: string]: any;
212
+ }
213
+
214
+ interface IOpts {
215
+ root: string;
216
+ relDir?: string;
217
+ componentPrefix?: string;
218
+ config: IConfig;
219
+ }
220
+ declare function getRoutes(opts: IOpts): IRoute[];
221
+
161
222
  /**
162
223
  * 微前端插件集合
163
- *
164
- * 整合了以下功能:
165
- * 1. HTML 转换 - 移除开发环境下的 React Refresh 脚本
166
- * 2. 路由自动生成 - 根据 pages 目录自动生成路由配置
167
- * 3. mf.tsx 生成器 - 自动生成模块联邦工具文件
168
- * 4. 模块联邦配置 - 使用 @originjs/vite-plugin-federation
169
- * 5. qiankun 微前端配置
170
- *
171
- * @example
172
- * ```ts
173
- * // vite.config.ts
174
- * import { microFrontendPlugins, createMfAlias } from '@anthropic/vite-plugin-micro-frontend';
175
- *
176
- * export default defineConfig({
177
- * plugins: [
178
- * ...microFrontendPlugins({
179
- * appName: 'wms',
180
- * useDevMode: process.env.NODE_ENV === 'development',
181
- * federation: {
182
- * name: 'wms',
183
- * filename: 'remote.js',
184
- * exposes: {
185
- * './ProcessingInboundDetail': './src/exposes/processing-inbound-detail/index.tsx',
186
- * },
187
- * remotes: {
188
- * ama: {
189
- * aliasName: 'ama',
190
- * remoteName: 'ama',
191
- * entry: '/app-ama/remote.js',
192
- * },
193
- * whs: {
194
- * aliasName: 'whs',
195
- * remoteName: 'whs',
196
- * entry: '/app-whs/remote.js',
197
- * },
198
- * },
199
- * },
200
- * routes: {
201
- * pagesDir: 'src/pages',
202
- * outputPath: 'src/routes.ts',
203
- * },
204
- * qiankun: {
205
- * enabled: true,
206
- * name: 'wms',
207
- * },
208
- * }),
209
- * ],
210
- * resolve: {
211
- * alias: {
212
- * ...createMfAlias(),
213
- * },
214
- * },
215
- * });
216
- * ```
224
+ * @param options 微前端插件选项
225
+ * @returns 插件数组
217
226
  */
218
227
  declare function microFrontendPlugins(options: MicroFrontendPluginOptions): PluginOption[];
219
- /**
220
- * 创建 resolve.alias 配置
221
- * 用于配置 mf.tsx 的别名
222
- */
223
- declare function createMfAlias(mfPath?: string): Record<string, string>;
224
228
 
225
- export { createMfAlias, dynamic, htmlRemoveFreshPlugin, mfGeneratorPlugin, microFrontendPlugins, pagesRoutesPlugin };
226
- export type { ComponentMetadata, DynamicOptions, FederationConfig, MfGeneratorOptions, MicroFrontendPluginOptions, RemoteConfig, RouteConfig, RoutesPluginOptions, RoutesTemplateOptions, VitePlugin };
229
+ export { dynamic, federationPlugin, getRoutes, htmlRemoveFreshPlugin, mfGeneratorPlugin, microFrontendPlugins, pagesRoutesPlugin };
230
+ export type { ComponentMetadata, DynamicOptions, FederationConfig, IRoute, MfGeneratorOptions, MicroFrontendPluginOptions, RemoteConfig, RouteConfig, RoutesPluginOptions, RoutesTemplateOptions, VitePlugin };