@module-federation/utilities 3.0.4 → 3.0.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/README.md +146 -0
- package/dist/package.json +54 -0
- package/package.json +8 -9
- /package/{index.cjs.d.ts → dist/index.cjs.d.ts} +0 -0
- /package/{index.cjs.default.js → dist/index.cjs.default.js} +0 -0
- /package/{index.cjs.js → dist/index.cjs.js} +0 -0
- /package/{index.cjs.mjs → dist/index.cjs.mjs} +0 -0
- /package/{index.esm.js → dist/index.esm.js} +0 -0
- /package/{src → dist/src}/Logger.d.ts +0 -0
- /package/{src → dist/src}/components/ErrorBoundary.d.ts +0 -0
- /package/{src → dist/src}/components/FederationBoundary.d.ts +0 -0
- /package/{src → dist/src}/index.d.ts +0 -0
- /package/{src → dist/src}/plugins/DelegateModulesPlugin.d.ts +0 -0
- /package/{src → dist/src}/types/index.d.ts +0 -0
- /package/{src → dist/src}/utils/common.d.ts +0 -0
- /package/{src → dist/src}/utils/getRuntimeRemotes.d.ts +0 -0
- /package/{src → dist/src}/utils/importDelegatedModule.d.ts +0 -0
- /package/{src → dist/src}/utils/importRemote.d.ts +0 -0
- /package/{src → dist/src}/utils/isEmpty.d.ts +0 -0
- /package/{src → dist/src}/utils/pure.d.ts +0 -0
- /package/{src → dist/src}/utils/react.d.ts +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# utils
|
|
2
|
+
|
|
3
|
+
This library was generated with [Nx](https://nx.dev).
|
|
4
|
+
|
|
5
|
+
## Building
|
|
6
|
+
|
|
7
|
+
Run `nx build utils` to build the library.
|
|
8
|
+
|
|
9
|
+
## Running unit tests
|
|
10
|
+
|
|
11
|
+
Run `nx test utils` to execute the unit tests via [Jest](https://jestjs.io).
|
|
12
|
+
|
|
13
|
+
## React utilities
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
`FederatedBoundary`
|
|
18
|
+
|
|
19
|
+
A component wrapper that provides a fallback for safe imports if something were to fail when grabbing a module off of a remote host.
|
|
20
|
+
|
|
21
|
+
This wrapper also exposes an optional property for a custom react error boundary component.
|
|
22
|
+
|
|
23
|
+
Any extra props will be passed directly to the imported module.
|
|
24
|
+
|
|
25
|
+
Usage looks something like this:
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
import { FederationBoundary } from '@module-federation/utilities/src/utils/react';
|
|
29
|
+
|
|
30
|
+
// defining dynamicImport and fallback outside the Component to keep the component identity
|
|
31
|
+
// another alternative would be to use useMemo
|
|
32
|
+
const dynamicImport = () => import('some_remote_host_name').then((m) => m.Component);
|
|
33
|
+
const fallback = () => import('@npm/backup').then((m) => m.Component);
|
|
34
|
+
|
|
35
|
+
const MyPage = () => {
|
|
36
|
+
return <FederationBoundary dynamicImporter={dynamicImport} fallback={fallback} customBoundary={CustomErrorBoundary} />;
|
|
37
|
+
};
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
`ImportRemote`
|
|
43
|
+
|
|
44
|
+
A function which will enable dynamic imports of remotely exposed modules using the Module Federation plugin. It uses the method described in the official Webpack configuration under <a href="https://webpack.js.org/concepts/module-federation/#dynamic-remote-containers" target="_blank">Dynamic Remote Containers</a>.
|
|
45
|
+
|
|
46
|
+
This function will allow you to provide a static url or an async method to retrieve a url from a configuration service.
|
|
47
|
+
|
|
48
|
+
Usage looks something like this:
|
|
49
|
+
|
|
50
|
+
```js
|
|
51
|
+
import { importRemote } from '@module-federation/utilities';
|
|
52
|
+
|
|
53
|
+
// --
|
|
54
|
+
// If it's a regular js module:
|
|
55
|
+
// --
|
|
56
|
+
importRemote({
|
|
57
|
+
url: 'http://localhost:3001',
|
|
58
|
+
scope: 'Foo',
|
|
59
|
+
module: 'Bar',
|
|
60
|
+
}).then(
|
|
61
|
+
(
|
|
62
|
+
{
|
|
63
|
+
/* list of Bar exports */
|
|
64
|
+
},
|
|
65
|
+
) => {
|
|
66
|
+
// Use Bar exports
|
|
67
|
+
},
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
// --
|
|
71
|
+
// If it's a ESM module (this is currently the default for NX):
|
|
72
|
+
// --
|
|
73
|
+
const Bar = lazy(() => importRemote({ url: 'http://localhost:3001', scope: 'Foo', module: 'Bar', esm: true }));
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<Suspense fallback={<div>Loading Bar...</div>}>
|
|
77
|
+
<Bar />
|
|
78
|
+
</Suspense>
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
// --
|
|
82
|
+
// If Bar is a React component you can use it with lazy and Suspense just like a dynamic import:
|
|
83
|
+
// --
|
|
84
|
+
const Bar = lazy(() => importRemote({ url: 'http://localhost:3001', scope: 'Foo', module: 'Bar' }));
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
<Suspense fallback={<div>Loading Bar...</div>}>
|
|
88
|
+
<Bar />
|
|
89
|
+
</Suspense>
|
|
90
|
+
);
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
```js
|
|
94
|
+
import { importRemote } from '@module-federation/utilities';
|
|
95
|
+
|
|
96
|
+
// If it's a regular js module:
|
|
97
|
+
importRemote({
|
|
98
|
+
url: () => MyAsyncMethod('remote_name'),
|
|
99
|
+
scope: 'Foo',
|
|
100
|
+
module: 'Bar',
|
|
101
|
+
}).then(
|
|
102
|
+
(
|
|
103
|
+
{
|
|
104
|
+
/* list of Bar exports */
|
|
105
|
+
},
|
|
106
|
+
) => {
|
|
107
|
+
// Use Bar exports
|
|
108
|
+
},
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
// If Bar is a React component you can use it with lazy and Suspense just like a dynamic import:
|
|
112
|
+
const Bar = lazy(() =>
|
|
113
|
+
importRemote({
|
|
114
|
+
url: () => MyAsyncMethod('remote_name'),
|
|
115
|
+
scope: 'Foo',
|
|
116
|
+
module: 'Bar',
|
|
117
|
+
}),
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
return (
|
|
121
|
+
<Suspense fallback={<div>Loading Bar...</div>}>
|
|
122
|
+
<Bar />
|
|
123
|
+
</Suspense>
|
|
124
|
+
);
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
```js
|
|
128
|
+
// You can also combine importRemote and FederationBoundary to have a dynamic remote URL and a fallback when there is an error on the remote
|
|
129
|
+
|
|
130
|
+
const dynamicImporter = () =>
|
|
131
|
+
importRemote({
|
|
132
|
+
url: 'http://localhost:3001',
|
|
133
|
+
scope: 'Foo',
|
|
134
|
+
module: 'Bar',
|
|
135
|
+
});
|
|
136
|
+
const fallback = () => import('@npm/backup').then((m) => m.Component);
|
|
137
|
+
|
|
138
|
+
const Bar = () => {
|
|
139
|
+
return <FederationBoundary dynamicImporter={dynamicImporter} fallback={fallback} />;
|
|
140
|
+
};
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Apart from **url**, **scope** and **module** you can also pass additional options to the **importRemote()** function:
|
|
144
|
+
|
|
145
|
+
- **remoteEntryFileName**: The name of the remote entry file. Defaults to "remoteEntry.js".
|
|
146
|
+
- **bustRemoteEntryCache**: Whether to add a cache busting query parameter to the remote entry file URL. Defaults to **true**. You can disable it if cachebusting is handled by the server.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@module-federation/utilities",
|
|
3
|
+
"version": "3.0.5",
|
|
4
|
+
"type": "commonjs",
|
|
5
|
+
"main": "./index.cjs.js",
|
|
6
|
+
"types": "./dist/index.cjs.d.ts",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist/",
|
|
13
|
+
"README.md"
|
|
14
|
+
],
|
|
15
|
+
"repository": "https://github.com/module-federation/universe/tree/main/packages/utilities",
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"react": "18.2.0"
|
|
18
|
+
},
|
|
19
|
+
"peerDependencies": {
|
|
20
|
+
"webpack": "^5.40.0",
|
|
21
|
+
"react-dom": "^16 || ^17 || ^18",
|
|
22
|
+
"react": "^16 || ^17 || ^18"
|
|
23
|
+
},
|
|
24
|
+
"peerDependenciesMeta": {
|
|
25
|
+
"react": {
|
|
26
|
+
"optional": true
|
|
27
|
+
},
|
|
28
|
+
"react-dom": {
|
|
29
|
+
"optional": true
|
|
30
|
+
},
|
|
31
|
+
"next": {
|
|
32
|
+
"optional": true
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"exports": {
|
|
36
|
+
".": {
|
|
37
|
+
"module": "./index.esm.js",
|
|
38
|
+
"import": "./index.cjs.mjs",
|
|
39
|
+
"default": "./index.cjs.js"
|
|
40
|
+
},
|
|
41
|
+
"./package.json": "./package.json"
|
|
42
|
+
},
|
|
43
|
+
"typesVersions": {
|
|
44
|
+
"*": {
|
|
45
|
+
".": [
|
|
46
|
+
"./dist/index.cjs.d.ts"
|
|
47
|
+
],
|
|
48
|
+
"type": [
|
|
49
|
+
"./dist/type.cjs.d.ts"
|
|
50
|
+
]
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"module": "./index.esm.js"
|
|
54
|
+
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/utilities",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.5",
|
|
4
4
|
"type": "commonjs",
|
|
5
|
-
"main": "./index.cjs.js",
|
|
5
|
+
"main": "./dist/index.cjs.js",
|
|
6
6
|
"types": "./dist/index.cjs.d.ts",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"publishConfig": {
|
|
9
9
|
"access": "public"
|
|
10
10
|
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist/",
|
|
13
|
+
"README.md"
|
|
14
|
+
],
|
|
11
15
|
"repository": "https://github.com/module-federation/universe/tree/main/packages/utilities",
|
|
12
16
|
"devDependencies": {
|
|
13
17
|
"react": "18.2.0"
|
|
@@ -29,11 +33,7 @@
|
|
|
29
33
|
}
|
|
30
34
|
},
|
|
31
35
|
"exports": {
|
|
32
|
-
".":
|
|
33
|
-
"module": "./index.esm.js",
|
|
34
|
-
"import": "./index.cjs.mjs",
|
|
35
|
-
"default": "./index.cjs.js"
|
|
36
|
-
},
|
|
36
|
+
".": "./dist/index.cjs.js",
|
|
37
37
|
"./package.json": "./package.json"
|
|
38
38
|
},
|
|
39
39
|
"typesVersions": {
|
|
@@ -45,6 +45,5 @@
|
|
|
45
45
|
"./dist/type.cjs.d.ts"
|
|
46
46
|
]
|
|
47
47
|
}
|
|
48
|
-
}
|
|
49
|
-
"module": "./index.esm.js"
|
|
48
|
+
}
|
|
50
49
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|