@module-federation/modern-js 0.0.0-next-20240701075157 → 0.0.0-next-20240712032032
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
CHANGED
|
@@ -2,166 +2,4 @@
|
|
|
2
2
|
|
|
3
3
|
This plugin provides Module Federation supporting functions for Modern.js
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
- modern.js ^2.54.2
|
|
8
|
-
- Server-Side Rendering
|
|
9
|
-
|
|
10
|
-
We highly recommend referencing this application which takes advantage of the best capabilities:
|
|
11
|
-
[module-federation example](https://github.com/module-federation/core/tree/feat/modernjs-ssr/apps/modernjs-ssr)
|
|
12
|
-
|
|
13
|
-
## Quick Start
|
|
14
|
-
|
|
15
|
-
### Installation
|
|
16
|
-
|
|
17
|
-
You can install the plugin with the following commands:
|
|
18
|
-
|
|
19
|
-
import { PackageManagerTabs } from '@theme';
|
|
20
|
-
|
|
21
|
-
<PackageManagerTabs
|
|
22
|
-
command={{
|
|
23
|
-
npm: 'npm add @module-federation/modern-js --save',
|
|
24
|
-
yarn: 'yarn add @module-federation/modern-js --save',
|
|
25
|
-
pnpm: 'pnpm add @module-federation/modern-js --save',
|
|
26
|
-
bun: 'bun add @module-federation/modern-js --save',
|
|
27
|
-
}}
|
|
28
|
-
/>
|
|
29
|
-
|
|
30
|
-
### Apply Plugin
|
|
31
|
-
|
|
32
|
-
Apply this plugin in `plugins` of `modern.config.ts`:
|
|
33
|
-
|
|
34
|
-
```ts title="modern.config.ts"
|
|
35
|
-
import { appTools, defineConfig } from '@modern-js/app-tools';
|
|
36
|
-
import { moduleFederationPlugin } from '@module-federation/modern-js';
|
|
37
|
-
|
|
38
|
-
export default defineConfig({
|
|
39
|
-
dev: {
|
|
40
|
-
port: 3005,
|
|
41
|
-
},
|
|
42
|
-
runtime: {
|
|
43
|
-
router: true,
|
|
44
|
-
},
|
|
45
|
-
// moduleFederationPlugin is a plug-in for modern.js, which can make certain modifications to the build/runtime
|
|
46
|
-
plugins: [appTools(), moduleFederationPlugin()],
|
|
47
|
-
});
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
Then create the `module-federation.config.ts` file and write the required configuration:
|
|
51
|
-
|
|
52
|
-
```ts title="module-federation.config.ts"
|
|
53
|
-
import { createModuleFederationConfig } from '@module-federation/modern-js';
|
|
54
|
-
export default createModuleFederationConfig({
|
|
55
|
-
name: 'host',
|
|
56
|
-
remotes: {
|
|
57
|
-
remote: 'remote@http://localhost:3006/mf-manifest.json',
|
|
58
|
-
},
|
|
59
|
-
shared: {
|
|
60
|
-
react: { singleton: true },
|
|
61
|
-
'react-dom': { singleton: true },
|
|
62
|
-
},
|
|
63
|
-
});
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
### Type support
|
|
67
|
-
|
|
68
|
-
add `/// <reference types='@module-federation/modern-js/types' />` in `modern-app-env.d.ts` to get type support.
|
|
69
|
-
|
|
70
|
-
```diff title='modern-app-env.d.ts'
|
|
71
|
-
+ /// <reference types='@module-federation/modern-js/types' />
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
## Server-Side Rendering
|
|
75
|
-
|
|
76
|
-
:::info
|
|
77
|
-
For a better performance experience, Module Federation X Modern.js SSR only supports stream SSR.
|
|
78
|
-
:::
|
|
79
|
-
|
|
80
|
-
There is no difference between using Module Federation in SSR scenarios and CSR scenarios. Developers can just keep following the original development behavior.
|
|
81
|
-
|
|
82
|
-
But for a better user experience, we provide supporting functions/components to help developers better use Module Federation.
|
|
83
|
-
|
|
84
|
-
### createRemoteSSRComponent
|
|
85
|
-
|
|
86
|
-
```ts
|
|
87
|
-
declare function createRemoteSSRComponent(
|
|
88
|
-
props: CreateRemoteSSRComponentOptions
|
|
89
|
-
): (props: ComponentType) => React.JSX.Element;
|
|
90
|
-
|
|
91
|
-
type CreateRemoteSSRComponentOptions = {
|
|
92
|
-
loader: () => Promise<T>;
|
|
93
|
-
loading: React.ReactNode;
|
|
94
|
-
fallback: ErrorBoundaryPropsWithComponent['FallbackComponent'];
|
|
95
|
-
export?: E;
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
type ComponentType = T[E] extends (...args: any) => any
|
|
99
|
-
? Parameters<T[E]>[0] extends undefined
|
|
100
|
-
? Record<string, never>
|
|
101
|
-
: Parameters<T[E]>[0]
|
|
102
|
-
: Record<string, never>;
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
This function will also help inject the corresponding style tag/script while loading the component. This behavior can help avoid the CSS flickering problem caused by streaming rendering and accelerate the PID (first screen interactive time).
|
|
106
|
-
|
|
107
|
-
#### Example
|
|
108
|
-
|
|
109
|
-
```tsx
|
|
110
|
-
import React, { FC, memo, useEffect } from 'react';
|
|
111
|
-
import { registerRemotes, createRemoteSSRComponent } from '@modern-js/runtime/mf';
|
|
112
|
-
// The remote declared in the build plug-in can be imported directly at the top level
|
|
113
|
-
import RemoteComp from 'remote/Image';
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
const RemoteSSRComponent = createRemoteSSRComponent({
|
|
117
|
-
// The remote declared in the build plug-in can also be loaded using this function: loader: () => import('remote/Image'),
|
|
118
|
-
loader: () => loadRemote('dynamic_remote/Image'),
|
|
119
|
-
loading: <div>loading...</div>,
|
|
120
|
-
fallback: ({ error }) => {
|
|
121
|
-
if (error instanceof Error && error.message.includes('not exist')) {
|
|
122
|
-
return <div>fallback - not existed id</div>;
|
|
123
|
-
}
|
|
124
|
-
return <div>fallback</div>;
|
|
125
|
-
},
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
const Product: FC = () => {
|
|
129
|
-
registerRemotes([
|
|
130
|
-
{
|
|
131
|
-
name: 'dynamic_remote',
|
|
132
|
-
entry: 'http://localhost:3008/mf-manifest.json',
|
|
133
|
-
},
|
|
134
|
-
]);
|
|
135
|
-
|
|
136
|
-
const fallback = (err: Error) => {
|
|
137
|
-
if (err.message.includes('does not exist in container')) {
|
|
138
|
-
return <div>404</div>;
|
|
139
|
-
}
|
|
140
|
-
throw err;
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
return <>
|
|
144
|
-
<RemoteSSRComponent />
|
|
145
|
-
<RemoteComp />
|
|
146
|
-
</>;
|
|
147
|
-
};
|
|
148
|
-
export default Product;
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
#### loading
|
|
152
|
-
|
|
153
|
-
- Type:`React.ReactNode`
|
|
154
|
-
- Required: Yes
|
|
155
|
-
- Default value: `undefined`
|
|
156
|
-
|
|
157
|
-
Set module loading status.
|
|
158
|
-
|
|
159
|
-
#### fallback
|
|
160
|
-
|
|
161
|
-
- Type:`((err: Error) => React.ReactElement)`
|
|
162
|
-
- Required: Yes
|
|
163
|
-
- Default value: `undefined`
|
|
164
|
-
|
|
165
|
-
A fault-tolerant component that is rendered when the component fails to **load** or **render**.
|
|
166
|
-
|
|
167
|
-
Note: This component only renders this fault-tolerant component on the client side when **rendering** fails.
|
|
5
|
+
See [documentation](https://module-federation.io/guide/framework/modernjs.html) for more details .
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var bundler_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(bundler_exports);
|
|
File without changes
|
|
File without changes
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { webpack, UserConfig, AppTools, Rspack } from '@modern-js/app-tools';
|
|
1
|
+
import type { webpack, UserConfig, AppTools, Rspack, Bundler } from '@modern-js/app-tools';
|
|
2
2
|
import { moduleFederationPlugin } from '@module-federation/sdk';
|
|
3
3
|
import { PluginOptions } from '../types';
|
|
4
|
+
import { BundlerConfig } from '../interfaces/bundler';
|
|
4
5
|
export type ConfigType<T> = T extends 'webpack' ? webpack.Configuration : T extends 'rspack' ? Rspack.Configuration : never;
|
|
5
6
|
export declare const getMFConfig: (userConfig: PluginOptions) => Promise<moduleFederationPlugin.ModuleFederationPluginOptions>;
|
|
6
7
|
export declare const patchMFConfig: (mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions, isServer: boolean) => {
|
|
@@ -39,8 +40,8 @@ export declare function getTargetEnvConfig(mfConfig: moduleFederationPlugin.Modu
|
|
|
39
40
|
dts?: boolean | moduleFederationPlugin.PluginDtsOptions;
|
|
40
41
|
async?: boolean | moduleFederationPlugin.AsyncBoundaryOptions;
|
|
41
42
|
};
|
|
42
|
-
export declare function patchWebpackConfig<T>(options: {
|
|
43
|
-
bundlerConfig:
|
|
43
|
+
export declare function patchWebpackConfig<T extends Bundler>(options: {
|
|
44
|
+
bundlerConfig: BundlerConfig<T>;
|
|
44
45
|
isServer: boolean;
|
|
45
46
|
modernjsConfig: UserConfig<AppTools>;
|
|
46
47
|
mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AppTools, Bundler } from '@modern-js/app-tools';
|
|
2
|
+
type AppToolsUserConfig<T extends Bundler> = AppTools<T>['userConfig']['tools'];
|
|
3
|
+
type ExcludeUndefined<T> = T extends undefined ? never : T;
|
|
4
|
+
type ExtractObjectType<T> = T extends (...args: any[]) => any ? never : T;
|
|
5
|
+
type OmitArrayConfiguration<T> = T extends Array<any> ? (T extends (infer U)[] ? U : T) : ExtractObjectType<T>;
|
|
6
|
+
type WebpackConfigs = ExcludeUndefined<AppToolsUserConfig<'webpack'>> extends {
|
|
7
|
+
webpack?: infer U;
|
|
8
|
+
} ? U : never;
|
|
9
|
+
type ObjectWebpack = ExtractObjectType<OmitArrayConfiguration<WebpackConfigs>>;
|
|
10
|
+
type RspackConfigs = ExcludeUndefined<AppToolsUserConfig<'rspack'>> extends {
|
|
11
|
+
rspack?: infer U;
|
|
12
|
+
} ? U : never;
|
|
13
|
+
type ObjectRspack = ExtractObjectType<OmitArrayConfiguration<RspackConfigs>>;
|
|
14
|
+
export type BundlerConfig<T extends Bundler> = T extends 'rspack' ? ObjectRspack : ObjectWebpack;
|
|
15
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/modern-js",
|
|
3
|
-
"version": "0.0.0-next-
|
|
3
|
+
"version": "0.0.0-next-20240712032032",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist/",
|
|
6
6
|
"types.d.ts",
|
|
@@ -43,27 +43,37 @@
|
|
|
43
43
|
"license": "MIT",
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@swc/helpers": "0.5.3",
|
|
46
|
-
"@modern-js/utils": "
|
|
47
|
-
"@modern-js/node-bundle-require": "
|
|
46
|
+
"@modern-js/utils": "2.54.2",
|
|
47
|
+
"@modern-js/node-bundle-require": "2.54.2",
|
|
48
48
|
"node-fetch": "~3.3.0",
|
|
49
49
|
"react-error-boundary": "4.0.13",
|
|
50
50
|
"hoist-non-react-statics": "3.3.2",
|
|
51
|
-
"@module-federation/sdk": "0.0.0-next-
|
|
52
|
-
"@module-federation/enhanced": "0.0.0-next-
|
|
53
|
-
"@module-federation/node": "0.0.0-next-
|
|
51
|
+
"@module-federation/sdk": "0.0.0-next-20240712032032",
|
|
52
|
+
"@module-federation/enhanced": "0.0.0-next-20240712032032",
|
|
53
|
+
"@module-federation/node": "0.0.0-next-20240712032032"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@types/hoist-non-react-statics": "3.3.2",
|
|
57
|
-
"@modern-js/app-tools": "^2.
|
|
58
|
-
"@modern-js/core": "^2.
|
|
59
|
-
"@modern-js/runtime": "^2.
|
|
60
|
-
"@modern-js/module-tools": "^2.
|
|
61
|
-
"@modern-js/tsconfig": "^2.
|
|
62
|
-
"@module-federation/manifest": "0.0.0-next-
|
|
57
|
+
"@modern-js/app-tools": "^2.55.0",
|
|
58
|
+
"@modern-js/core": "^2.55.0",
|
|
59
|
+
"@modern-js/runtime": "^2.55.0",
|
|
60
|
+
"@modern-js/module-tools": "^2.55.0",
|
|
61
|
+
"@modern-js/tsconfig": "^2.55.0",
|
|
62
|
+
"@module-federation/manifest": "0.0.0-next-20240712032032"
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
65
65
|
"react": ">=17",
|
|
66
|
-
"react-dom": ">=17"
|
|
66
|
+
"react-dom": ">=17",
|
|
67
|
+
"typescript": "^4.9.0 || ^5.0.0",
|
|
68
|
+
"vue-tsc": "^1.0.24"
|
|
69
|
+
},
|
|
70
|
+
"peerDependenciesMeta": {
|
|
71
|
+
"typescript": {
|
|
72
|
+
"optional": true
|
|
73
|
+
},
|
|
74
|
+
"vue-tsc": {
|
|
75
|
+
"optional": true
|
|
76
|
+
}
|
|
67
77
|
},
|
|
68
78
|
"scripts": {
|
|
69
79
|
"build": "modern build"
|