@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 +39 -49
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/runtime-react-refresh-init.d.ts +2 -0
- package/dist/runtime-react-refresh-init.js +71 -0
- package/dist/runtime-react-refresh-init.js.map +1 -0
- package/dist/runtime.js +2 -27756
- package/dist/runtime.js.map +1 -1
- package/package.json +9 -3
- package/dist/modules.d.ts +0 -34
|
@@ -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,CAAC,KAAK;AAAE,QAAA,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC;IAErC,IAAI,oBAAoB,GAAmC,IAAI;AAE/D,IAAA,MAAM,kBAAkB,GAAG,YAAoC;AAC7D,QAAA,IAAI,oBAAoB;AAAE,YAAA,OAAO,oBAAoB;QAErD,MAAM,QAAQ,GACX,GAAG,CAAC,KAA0D,EAAE,mCAAmC,IAAI,EAAE;QAC5G,MAAM,WAAW,GAAG,QAAQ,GAAG,CAAA,EAAG,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA,eAAA,CAAiB,GAAG,gBAAgB;AAEjG,QAAA,oBAAoB,GAAG,0BAA0B,WAAW,CAAC,CAAC,IAAI,CAChE,CAAC,CAAC,KAAK,CAAC,CAAC,OAAyB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