@lemon-fe/vite-plugin-micro-frontend 1.2.0 → 1.2.2

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 CHANGED
@@ -201,7 +201,23 @@ export default defineConfig({
201
201
  | `intlPath` | `string` | `'@/utils/intl'` | 国际化工具路径 |
202
202
  | `pageAliasPrefix` | `string` | `'@/pages'` | 页面别名前缀 |
203
203
 
204
- > 注意:`dynamic` 函数已内置到插件中,通过虚拟模块 `virtual:micro-frontend/dynamic` 提供,无需额外配置。
204
+ > 注意:`dynamic` 请从 `@lemon-fe/vite-plugin-micro-frontend/runtime/dynamic` 引入(不含 qiankun);`renderWithQiankun` 请从 `runtime/qiankun` 引入且仅用于 `main.tsx`。旧路径 `./runtime` 仍可用,但不建议在新代码中使用。
205
+
206
+ ### Runtime 子路径
207
+
208
+ | 子路径 | 用途 | 依赖 |
209
+ | ------ | ---- | ---- |
210
+ | `runtime/dynamic` | 路由 / 业务组件 lazy load | 仅 `react` |
211
+ | `runtime/qiankun` | 子应用 bootstrap(`main.tsx`) | `vite-plugin-qiankun` |
212
+ | `runtime` | 兼容聚合入口 | 上述两者 re-export |
213
+
214
+ ```typescript
215
+ // routes.ts / 业务组件
216
+ import { dynamic } from "@lemon-fe/vite-plugin-micro-frontend/runtime/dynamic";
217
+
218
+ // main.tsx
219
+ import { renderWithQiankun } from "@lemon-fe/vite-plugin-micro-frontend/runtime/qiankun";
220
+ ```
205
221
 
206
222
  ## 路由约定
207
223
 
package/dist/index.d.ts CHANGED
@@ -39,6 +39,40 @@ declare function mfGeneratorPlugin(options: MfGeneratorOptions): VitePlugin;
39
39
  */
40
40
  declare function federationPlugin(federationOptions: FederationConfig): PluginOption[];
41
41
 
42
+ /**
43
+ * 生产构建动态 publicPath(类似 webpack `output.publicPath`)。
44
+ * 依赖 [vite-plugin-dynamic-base](https://github.com/chenxch/vite-plugin-dynamic-base);
45
+ * 生产环境请在应用的 `vite.config` 中使用占位 `base`,例如:
46
+ * `base: process.env.NODE_ENV === "production" ? "/__dynamic_base__/" : "/"`。
47
+ * 插件本身仅作用于 `vite build`(`apply: 'build'`),开发服务器不会启用。
48
+ *
49
+ * 推荐写法:只写「固定变量」取到的**动态域名**(`runtimeHostExpr`),应用路径与 Vite `base` 对齐(`appBase` 或与当前 `base` 一致)。
50
+ */
51
+ type DynamicBaseConfig = {
52
+ /** 传给 vite-plugin-dynamic-base,默认 true */
53
+ transformIndexHtml?: boolean;
54
+ transformIndexHtmlConfig?: {
55
+ insertBodyAfter?: boolean;
56
+ publicPath?: string;
57
+ };
58
+ /**
59
+ * 运行时代码表达式:求值为**域名或 origin 前缀**(不要包含应用 path),用于拼接真实 CDN/网关地址。
60
+ * 变量名固定(如 `window.EARTH_BASE_CONFIG.EARTH_ALL_SHARE_HOST`),值为运行时动态域名。
61
+ * 示例:`"(window.EARTH_BASE_CONFIG && window.EARTH_BASE_CONFIG.EARTH_ALL_SHARE_HOST ? window.EARTH_BASE_CONFIG.EARTH_ALL_SHARE_HOST.replace(/\\\\/$/, '') : '') + '/app-earth-wms'"`
62
+ */
63
+ publicPath?: string;
64
+ /**
65
+ * 移除 HTML 中 `index-*.css` 的 link 与 dynamicBase 注入的对应 preload(样式全部由 JS 注入时使用)。
66
+ */
67
+ removeIndexCssPreload?: boolean;
68
+ };
69
+
70
+ /**
71
+ * 生产构建专用:动态 publicPath(vite-plugin-dynamic-base + 可选 HTML 兜底)。
72
+ * 仅 `vite build` 生效,与 {@link MicroFrontendPluginOptions.dynamicBase} 配合使用。
73
+ */
74
+ declare function getDynamicBasePlugins(options: DynamicBaseConfig | boolean): PluginOption[];
75
+
42
76
  declare function autoExternalAntd(): Plugin;
43
77
 
44
78
  /**
@@ -159,6 +193,8 @@ interface MicroFrontendPluginOptions {
159
193
  /** qiankun 应用名称 */
160
194
  name?: string;
161
195
  };
196
+ /** 生产构建启用动态资源路径;未配置则不注册 */
197
+ dynamicBase?: DynamicBaseConfig | boolean;
162
198
  }
163
199
  type VitePlugin = Plugin;
164
200
 
@@ -211,5 +247,5 @@ declare function getRoutes(opts: IOpts): IRoute[];
211
247
  declare const MICRO_FRONTEND_OPTIONS_KEY = "__microFrontendOptions";
212
248
  declare function microFrontendPlugins(options: MicroFrontendPluginOptions): PluginOption[];
213
249
 
214
- export { MICRO_FRONTEND_OPTIONS_KEY, autoExternalAntd, devHmrPlugin, federationPlugin, generateMf, generateRoutesToFile, getRoutes, mfGeneratorPlugin, microFrontendPlugins, pagesRoutesPlugin };
215
- export type { ComponentMetadata, FederationConfig, IRoute, MfGeneratorOptions, MicroFrontendPluginOptions, RemoteConfig, RouteConfig, RoutesPluginOptions, RoutesTemplateOptions, VitePlugin };
250
+ export { MICRO_FRONTEND_OPTIONS_KEY, autoExternalAntd, devHmrPlugin, federationPlugin, generateMf, generateRoutesToFile, getDynamicBasePlugins, getRoutes, mfGeneratorPlugin, microFrontendPlugins, pagesRoutesPlugin };
251
+ export type { ComponentMetadata, DynamicBaseConfig, FederationConfig, IRoute, MfGeneratorOptions, MicroFrontendPluginOptions, RemoteConfig, RouteConfig, RoutesPluginOptions, RoutesTemplateOptions, VitePlugin };