@lemon-fe/vite-plugin-micro-frontend 2.0.0 → 2.0.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.
@@ -1,5 +1,33 @@
1
1
  export { loadRemote } from '@module-federation/runtime';
2
2
 
3
+ interface DevelopmentApplication {
4
+ name: string;
5
+ entry: string;
6
+ module: string;
7
+ }
8
+ interface LoadDevelopmentRootOptions {
9
+ appName: string;
10
+ /** 消费应用的 MF name,默认由 appName 推导。 */
11
+ federationName?: string;
12
+ }
13
+ interface BaseRootProps {
14
+ localApplications: Record<string, DevelopmentApplication>;
15
+ }
16
+ type BaseRootComponent = (props: BaseRootProps) => unknown;
17
+ interface BaseRoot {
18
+ BaseRoot: BaseRootComponent;
19
+ createElement(component: BaseRootComponent, props: BaseRootProps): unknown;
20
+ createRenderer(container: HTMLElement): {
21
+ render(element: unknown): void;
22
+ unmount(): void;
23
+ };
24
+ }
25
+ interface DevelopmentRoot extends BaseRoot {
26
+ props: BaseRootProps;
27
+ }
28
+ /** 加载基座根组件,并提供本地应用的联邦入口。 */
29
+ declare function loadDevelopmentRoot({ appName, federationName, }: LoadDevelopmentRootOptions): Promise<DevelopmentRoot>;
30
+
3
31
  /** 保留直接使用官方默认实例的兼容入口。生成器使用下面的实例绑定加载器。 */
4
32
 
5
33
  interface RemoteLoaderOptions {
@@ -15,5 +43,5 @@ interface RemoteLoaderOptions {
15
43
  /** 动态加载不会经过 Vite 的静态 remote import 转换,必须显式注册到消费应用的实例。 */
16
44
  declare function createRemoteLoader(options: RemoteLoaderOptions): <T>(moduleSpecifier: string) => Promise<T | null>;
17
45
 
18
- export { createRemoteLoader };
19
- export type { RemoteLoaderOptions };
46
+ export { createRemoteLoader, loadDevelopmentRoot };
47
+ export type { DevelopmentApplication, LoadDevelopmentRootOptions, RemoteLoaderOptions };
@@ -1,6 +1,39 @@
1
- import { getInstance } from '@module-federation/runtime';
1
+ import { createInstance, getInstance } from '@module-federation/runtime';
2
2
  export { loadRemote } from '@module-federation/runtime';
3
3
 
4
+ /** 加载基座根组件,并提供本地应用的联邦入口。 */
5
+ async function loadDevelopmentRoot({ appName, federationName, }) {
6
+ const { basePath, remoteName, gatewayOrigin } = __MICRO_FRONTEND_DEVELOPMENT_SHELL__;
7
+ const localName = federationName || appName.replace(/-/g, '_');
8
+ const origin = window.location.origin;
9
+ const baseURL = `${origin}${basePath}`;
10
+ const shell = createInstance({
11
+ name: `${localName}_development_shell`,
12
+ remotes: [{ name: remoteName, entry: `${baseURL}/remote.js`, type: 'module' }],
13
+ shareStrategy: 'loaded-first',
14
+ });
15
+ const root = await shell.loadRemote(`${remoteName}/root`);
16
+ if (!root?.loadBaseRoot) {
17
+ throw new Error('目标基座未提供 root/loadBaseRoot,请先部署新版基座');
18
+ }
19
+ const base = await root.loadBaseRoot({
20
+ baseURL,
21
+ gatewayBaseURL: gatewayOrigin,
22
+ reactScripts: {
23
+ react: '/@micro-frontend/host-react.js',
24
+ reactDOM: '/@micro-frontend/host-react-dom.js',
25
+ },
26
+ });
27
+ return {
28
+ ...base,
29
+ props: {
30
+ localApplications: {
31
+ [appName]: { name: localName, entry: `${origin}/remote.js`, module: `${localName}/app` },
32
+ },
33
+ },
34
+ };
35
+ }
36
+
4
37
  /** 动态加载不会经过 Vite 的静态 remote import 转换,必须显式注册到消费应用的实例。 */
5
38
  function createRemoteLoader(options) {
6
39
  const registeredInstances = new WeakSet();
@@ -32,5 +65,5 @@ function createRemoteLoader(options) {
32
65
  };
33
66
  }
34
67
 
35
- export { createRemoteLoader };
68
+ export { createRemoteLoader, loadDevelopmentRoot };
36
69
  //# sourceMappingURL=runtime-federation.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"runtime-federation.js","sources":["../src/runtime/federation.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAqBA;AACM,SAAU,kBAAkB,CAAC,OAA4B,EAAA;AAC7D,IAAA,MAAM,mBAAmB,GAAG,IAAI,OAAO,EAAoB;IAE3D,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AAC;AAChD,IAAA,CAAC;AACH;;;;"}
1
+ {"version":3,"file":"runtime-federation.js","sources":["../src/runtime/development.ts","../src/runtime/federation.ts"],"sourcesContent":[null,null],"names":[],"mappings":";;;AA4CA;AACO,eAAe,mBAAmB,CAAC,EACxC,OAAO,EACP,cAAc,GACa,EAAA;IAC3B,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,aAAa,EAAE,GAAG,oCAAoC;AACpF,IAAA,MAAM,SAAS,GAAG,cAAc,IAAI,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC;AAC9D,IAAA,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM;AACrC,IAAA,MAAM,OAAO,GAAG,CAAA,EAAG,MAAM,CAAA,EAAG,QAAQ,EAAE;IACtC,MAAM,KAAK,GAAG,cAAc,CAAC;QAC3B,IAAI,EAAE,CAAA,EAAG,SAAS,CAAA,kBAAA,CAAoB;AACtC,QAAA,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,CAAA,EAAG,OAAO,CAAA,UAAA,CAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;AAC9E,QAAA,aAAa,EAAE,cAAc;AAC9B,KAAA,CAAC;IACF,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,UAAU,CAAiB,CAAA,EAAG,UAAU,CAAA,KAAA,CAAO,CAAC;AACzE,IAAA,IAAI,CAAC,IAAI,EAAE,YAAY,EAAE;AACvB,QAAA,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC;IACvD;AAEA,IAAA,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC;QACnC,OAAO;AACP,QAAA,cAAc,EAAE,aAAa;AAC7B,QAAA,YAAY,EAAE;AACZ,YAAA,KAAK,EAAE,gCAAgC;AACvC,YAAA,QAAQ,EAAE,oCAAoC;AAC/C,SAAA;AACF,KAAA,CAAC;IAEF,OAAO;AACL,QAAA,GA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ACL,IAAI,EAAE,MAAM,CAAC,UAAU,GAAG,QAAQ,GAAG,KAAK;oBAC1C,eAAe,EAAE,MAAM,CAAC,UAAU;AAClC,oBAAA,UAAU,EAAE,OAAO,CAAC,UAAU,IAAI,SAAS;iBAC5C;AACH,YAAA,CAAC,CAAC;;AAEF,YAAA,QAAQ,CAAC,eAAe,CAAC,OAAO,CAAC;AACjC,YAAA,mBAAmB,CAAC,GAAG,CAAC,QAAQ,CAAC;QACnC;AAEA,QAAA,OAAO,QAAQ,CAAC,UAAU,CAAI,eAAe,CAAC;AAChD,IAAA,CAAC;AACH;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lemon-fe/vite-plugin-micro-frontend",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "基于 Module Federation Runtime 与 React 组件的 Vite 微前端插件集合",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -9,44 +9,24 @@
9
9
  "mf": "./dist/cli.js"
10
10
  },
11
11
  "exports": {
12
- ".": {
13
- "types": "./dist/index.d.ts",
14
- "default": "./dist/index.js"
15
- },
16
- "./runtime": {
17
- "types": "./dist/runtime.d.ts",
18
- "default": "./dist/runtime.js"
19
- },
20
- "./runtime/dynamic": {
21
- "types": "./dist/runtime-dynamic.d.ts",
22
- "default": "./dist/runtime-dynamic.js"
23
- },
24
- "./runtime/app": {
25
- "types": "./dist/runtime-app.d.ts",
26
- "default": "./dist/runtime-app.js"
27
- },
28
- "./runtime/federation": {
29
- "types": "./dist/runtime-federation.d.ts",
30
- "default": "./dist/runtime-federation.js"
31
- },
32
- "./runtime/react-refresh-init": {
33
- "types": "./dist/runtime-react-refresh-init.d.ts",
34
- "default": "./dist/runtime-react-refresh-init.js"
35
- }
12
+ ".": "./dist/index.js",
13
+ "./runtime": "./dist/runtime.js",
14
+ "./runtime/dynamic": "./dist/runtime-dynamic.js",
15
+ "./runtime/app": "./dist/runtime-app.js",
16
+ "./runtime/federation": "./dist/runtime-federation.js",
17
+ "./runtime/development": "./dist/runtime-federation.js",
18
+ "./runtime/react-refresh-init": "./dist/runtime-react-refresh-init.js"
36
19
  },
37
20
  "typesVersions": {
38
21
  "*": {
39
22
  "runtime": [
40
23
  "./dist/runtime.d.ts"
41
24
  ],
42
- "runtime/dynamic": [
43
- "./dist/runtime-dynamic.d.ts"
44
- ],
45
- "runtime/app": [
46
- "./dist/runtime-app.d.ts"
47
- ],
48
- "runtime/federation": [
25
+ "runtime/development": [
49
26
  "./dist/runtime-federation.d.ts"
27
+ ],
28
+ "runtime/*": [
29
+ "./dist/runtime-*.d.ts"
50
30
  ]
51
31
  }
52
32
  },