@lemon-fe/vite-plugin-micro-frontend 1.1.4 → 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.
@@ -0,0 +1,2 @@
1
+
2
+ export { };
@@ -0,0 +1,71 @@
1
+ /// <reference types="vite/client" />
2
+ /// <reference path="./react-refresh-init.d.ts" />
3
+ /**
4
+ * React Refresh 初始化
5
+ * 在微前端 proxy 环境下支持 HMR,必须在入口最顶部被加载(由插件自动注入)。
6
+ *
7
+ * 注意:当前使用 React 17,不支持完整的 React Refresh,使用页面刷新作为回退方案
8
+ */
9
+ const isDev = import.meta.env?.DEV ?? false;
10
+ if (isDev) {
11
+ const win = window;
12
+ /** 在指定 window 上设置 preamble,供 @vitejs/plugin-react 与乾坤 proxy 使用 */
13
+ const setPreamble = (target) => {
14
+ if (!target.$RefreshReg$)
15
+ target.$RefreshReg$ = () => { };
16
+ if (!target.$RefreshSig$)
17
+ target.$RefreshSig$ = () => (type) => type;
18
+ target.__vite_plugin_react_preamble_installed__ = true;
19
+ };
20
+ setPreamble(win);
21
+ if (win.proxy)
22
+ setPreamble(win.proxy);
23
+ let refreshModulePromise = null;
24
+ const loadRefreshRuntime = async () => {
25
+ if (refreshModulePromise)
26
+ return refreshModulePromise;
27
+ const basePath = win.proxy?.__INJECTED_PUBLIC_PATH_BY_QIANKUN__ ?? '';
28
+ const refreshPath = basePath ? `${basePath.replace(/\/$/, '')}/@react-refresh` : '@react-refresh';
29
+ refreshModulePromise = import(/* @vite-ignore */ refreshPath).then((m) => m.default);
30
+ return refreshModulePromise;
31
+ };
32
+ loadRefreshRuntime()
33
+ .then((RefreshRuntime) => {
34
+ RefreshRuntime.injectIntoGlobalHook(win);
35
+ win.__vite_plugin_react_preamble_installed__ = true;
36
+ if (win.proxy) {
37
+ RefreshRuntime.injectIntoGlobalHook(win.proxy);
38
+ win.proxy.__vite_plugin_react_preamble_installed__ = true;
39
+ }
40
+ const checkRefreshSupport = () => {
41
+ const target = (win.proxy || win);
42
+ const hook = target.__REACT_DEVTOOLS_GLOBAL_HOOK__;
43
+ if (!hook?.renderers)
44
+ return false;
45
+ for (const renderer of hook.renderers.values()) {
46
+ const r = renderer;
47
+ if (typeof r?.scheduleRefresh === 'function' && typeof r?.setRefreshHandler === 'function')
48
+ return true;
49
+ }
50
+ return false;
51
+ };
52
+ if (import.meta.hot) {
53
+ import.meta.hot.on('vite:afterUpdate', () => {
54
+ if (!checkRefreshSupport()) {
55
+ setTimeout(() => {
56
+ if (typeof window !== 'undefined' && window.location)
57
+ window.location.reload();
58
+ }, 100);
59
+ }
60
+ });
61
+ import.meta.hot.on('vite:error', (err) => {
62
+ console.error('[React Refresh] HMR error:', err);
63
+ });
64
+ }
65
+ })
66
+ .catch((error) => {
67
+ console.error('[React Refresh] Failed to initialize runtime:', error);
68
+ console.error('[React Refresh] HMR will not work. Please check the error above.');
69
+ });
70
+ }
71
+ //# sourceMappingURL=runtime-react-refresh-init.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-react-refresh-init.js","sources":["../src/runtime/react-refresh-init.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAA;AACA;AACA;;;;;AAKG;AAUH,MAAM,KAAK,GAAI,MAAM,CAAC,IAAoC,CAAC,GAAG,EAAE,GAAG,IAAI,KAAK;AAE5E,IAAI,KAAK,EAAE;IACT,MAAM,GAAG,GAAG,MAAM;;AAGlB,IAAA,MAAM,WAAW,GAAG,CAAC,MAAc,KAAU;QAC3C,IAAI,CAAC,MAAM,CAAC,YAAY;AAAE,YAAA,MAAM,CAAC,YAAY,GAAG,MAAK,EAAE,CAAC;QACxD,IAAI,CAAC,MAAM,CAAC,YAAY;AACtB,YAAA,MAAM,CAAC,YAAY,GAAG,MAAM,CAAC,IAAa,KAAK,IAAI;AACrD,QAAA,MAAM,CAAC,wCAAwC,GAAG,IAAI;AACxD,IAAA,CAAC;IAED,WAAW,CAAC,GAAG,CAAC;IAChB,IAAI,GAAG,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UAAU,IAAI,OAAO,CAAC,EAAE,iBAAiB,KAAK,UAAU;AACxF,oBAAA,OAAO,IAAI;YACf;AACA,YAAA,OAAO,KAAK;AACd,QAAA,CAAC;AAED,QAAA,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE;YACnB,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,kBAAkB,EAAE,MAAK;AAC1C,gBAAA,IAAI,CAAC,mBAAmB,EAAE,EAAE;oBAC1B,UAAU,CAAC,MAAK;AACd,wBAAA,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,QAAQ;AAAE,4BAAA,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE;oBAChF,CAAC,EAAE,GAAG,CAAC;gBACT;AACF,YAAA,CAAC,CAAC;AACF,YAAA,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,YAAY,EAAE,CAAC,GAAY,KAAI;AAChD,gBAAA,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,GAAG,CAAC;AAClD,YAAA,CAAC,CAAC;QACJ;AACF,IAAA,CAAC;AACA,SAAA,KAAK,CAAC,CAAC,KAAK,KAAI;AACf,QAAA,OAAO,CAAC,KAAK,CAAC,+CAA+C,EAAE,KAAK,CAAC;AACrE,QAAA,OAAO,CAAC,KAAK,CAAC,kEAAkE,CAAC;AACnF,IAAA,CAAC,CAAC;AACN"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lemon-fe/vite-plugin-micro-frontend",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
4
4
  "description": "Vite 微前端插件集合,包含路由自动生成、模块联邦、qiankun 集成等功能",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -32,7 +32,7 @@
32
32
  "dist"
33
33
  ],
34
34
  "scripts": {
35
- "build": "rollup -c && cp src/types/modules.d.ts dist/modules.d.ts",
35
+ "build": "rollup -c",
36
36
  "dev": "rollup -c -w",
37
37
  "prepublishOnly": "npm run build"
38
38
  },
@@ -55,6 +55,7 @@
55
55
  "vite": "^4.0.0 || ^5.0.0"
56
56
  },
57
57
  "dependencies": {
58
+ "@module-federation/dts-plugin": "^0.21.6",
58
59
  "@module-federation/vite": "^1.9.4",
59
60
  "chokidar": "^4.0.3",
60
61
  "prettier": "^3.5.3",
package/dist/modules.d.ts DELETED
@@ -1,34 +0,0 @@
1
- /**
2
- * 模块声明文件
3
- * 为项目中使用的模块提供类型声明
4
- */
5
-
6
- declare module "@/routes" {
7
- import { type IRoute } from "@lemon-fe/kits/es/layouts/typings";
8
- export const routers: IRoute[];
9
- }
10
-
11
- declare module "@@/mf" {
12
- import { type ComponentType, type ReactNode } from "react";
13
-
14
- export function getEntryShared<T>(
15
- moduleSpecifier: string,
16
- getData: () => Promise<T>
17
- ): Promise<T>;
18
-
19
- type ExtractProps<T> = T extends ComponentType<infer P> ? P : T;
20
-
21
- export function safeRemoteComponent<T>(options: {
22
- loader?: () => Promise<{ default: ComponentType<ExtractProps<T>> }>;
23
- moduleSpecifier: string;
24
- fallbackComponent: ComponentType<ExtractProps<T>> | ComponentType<object>;
25
- loadingElement: ReactNode | null;
26
- }): ComponentType<ExtractProps<T>>;
27
-
28
- export function createRemoteComponent<T = Record<string, unknown>>(options: {
29
- loader: () => Promise<{ default: ComponentType<ExtractProps<T>> }>;
30
- moduleSpecifier: string;
31
- fallbackComponent: ComponentType<ExtractProps<T>> | ComponentType<object>;
32
- loadingElement: ReactNode | null;
33
- }): ComponentType<ExtractProps<T>>;
34
- }