remote-reload-utils 0.0.3 → 0.0.4
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/loadRemote.md +43 -0
- package/package.json +3 -2
package/loadRemote.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
```ts
|
|
2
|
+
import './App.css';
|
|
3
|
+
import { loadRemoteMultiVersion } from 'remote-reload-utils';
|
|
4
|
+
import { useEffect, useState } from 'react';
|
|
5
|
+
|
|
6
|
+
const App = () => {
|
|
7
|
+
const [comp, setComp] = useState(null);
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
async function init() {
|
|
10
|
+
const { scopeName, mf } = await loadRemoteMultiVersion({
|
|
11
|
+
name: 'react_mf_lib',
|
|
12
|
+
pkg: 'test-mf-unpkg',
|
|
13
|
+
version: '1.0.5',
|
|
14
|
+
// version: 'latest',
|
|
15
|
+
});
|
|
16
|
+
if (!mf) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (mf) {
|
|
20
|
+
console.log(mf);
|
|
21
|
+
const mod = await mf.loadRemote(`${scopeName}/Button`);
|
|
22
|
+
console.log(mod.default); // 这里就是远程组件
|
|
23
|
+
setComp(mod.default);
|
|
24
|
+
}
|
|
25
|
+
// 用 mf 实例加载暴露的模块
|
|
26
|
+
// const mod = await mf.loadRemote(`${scopeName}/Button`);
|
|
27
|
+
// const mod = await mf.loadRemote(`react_mf_lib/Button`);
|
|
28
|
+
// console.log(mod.default);
|
|
29
|
+
}
|
|
30
|
+
init();
|
|
31
|
+
}, []);
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<div className="content">
|
|
35
|
+
<h1>Rsbuild with React</h1>
|
|
36
|
+
{comp}
|
|
37
|
+
<p>Start building amazing things with Rsbuild.</p>
|
|
38
|
+
</div>
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export default App;
|
|
43
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "remote-reload-utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"main": "./dist/index.cjs",
|
|
13
13
|
"types": "./dist/index.d.ts",
|
|
14
14
|
"files": [
|
|
15
|
-
"dist"
|
|
15
|
+
"dist",
|
|
16
|
+
"loadRemote.md"
|
|
16
17
|
],
|
|
17
18
|
"scripts": {
|
|
18
19
|
"build": "rslib build",
|