@nx/react 20.1.0-canary.20241101-d4f4dac → 20.1.0-canary.20241102-c290b37
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/mf/dynamic-federation.d.ts +64 -0
- package/mf/dynamic-federation.js +64 -0
- package/package.json +5 -5
- package/src/generators/application/files/base-rspack/src/main.tsx__tmpl__ +3 -2
- package/src/generators/application/lib/create-application-files.js +2 -0
- package/src/generators/host/files/common/src/app/__fileName__.js__tmpl__ +10 -3
- package/src/generators/host/files/common/src/main.js__tmpl__ +6 -3
- package/src/generators/host/files/common-ts/src/app/__fileName__.tsx__tmpl__ +7 -7
- package/src/generators/host/files/common-ts/src/main.ts__tmpl__ +7 -4
- package/src/generators/host/files/rspack-common/src/app/__fileName__.jsx__tmpl__ +12 -3
- package/src/generators/host/files/rspack-common/src/main.jsx__tmpl__ +6 -3
- package/src/generators/host/host.js +3 -1
- package/src/generators/host/lib/add-module-federation-files.js +1 -1
@@ -1,5 +1,69 @@
|
|
1
1
|
export type ResolveRemoteUrlFunction = (remoteName: string) => string | Promise<string>;
|
2
|
+
/**
|
3
|
+
* @deprecated Use Runtime Helpers from '@module-federation/enhanced/runtime' instead. This will be removed in Nx 22.
|
4
|
+
*/
|
2
5
|
export declare function setRemoteUrlResolver(_resolveRemoteUrl: ResolveRemoteUrlFunction): void;
|
6
|
+
/**
|
7
|
+
* @deprecated Use init() from '@module-federation/enhanced/runtime' instead. This will be removed in Nx 22.
|
8
|
+
* If you have a remote app called `my-remote-app` and you want to use the `http://localhost:4201/mf-manifest.json` as the remote url, you should change it from:
|
9
|
+
* ```ts
|
10
|
+
* import { setRemoteDefinitions } from '@nx/react/mf';
|
11
|
+
*
|
12
|
+
* setRemoteDefinitions({
|
13
|
+
* 'my-remote-app': 'http://localhost:4201/mf-manifest.json'
|
14
|
+
* });
|
15
|
+
* ```
|
16
|
+
* to use init():
|
17
|
+
* ```ts
|
18
|
+
* import { init } from '@module-federation/enhanced/runtime';
|
19
|
+
*
|
20
|
+
* init({
|
21
|
+
* name: 'host',
|
22
|
+
* remotes: [{
|
23
|
+
* name: 'my-remote-app',
|
24
|
+
* entry: 'http://localhost:4201/mf-manifest.json'
|
25
|
+
* }]
|
26
|
+
* });
|
27
|
+
* ```
|
28
|
+
*/
|
3
29
|
export declare function setRemoteDefinitions(definitions: Record<string, string>): void;
|
30
|
+
/**
|
31
|
+
* @deprecated Use registerRemotes() from '@module-federation/enhanced/runtime' instead. This will be removed in Nx 22.
|
32
|
+
* If you set a remote app with `setRemoteDefinition` such as:
|
33
|
+
* ```ts
|
34
|
+
* import { setRemoteDefinition } from '@nx/react/mf';
|
35
|
+
*
|
36
|
+
* setRemoteDefinition(
|
37
|
+
* 'my-remote-app',
|
38
|
+
* 'http://localhost:4201/mf-manifest.json'
|
39
|
+
* );
|
40
|
+
* ```
|
41
|
+
* change it to use registerRemotes():
|
42
|
+
* ```ts
|
43
|
+
* import { registerRemotes } from '@module-federation/enhanced/runtime';
|
44
|
+
*
|
45
|
+
* registerRemotes([
|
46
|
+
* {
|
47
|
+
* name: 'my-remote-app',
|
48
|
+
* entry: 'http://localhost:4201/mf-manifest.json'
|
49
|
+
* }
|
50
|
+
* ]);
|
51
|
+
* ```
|
52
|
+
*/
|
4
53
|
export declare function setRemoteDefinition(remoteName: string, remoteUrl: string): void;
|
54
|
+
/**
|
55
|
+
* @deprecated Use loadRemote() from '@module-federation/enhanced/runtime' instead. This will be removed in Nx 22.
|
56
|
+
* If you set a load a remote with `loadRemoteModule` such as:
|
57
|
+
* ```ts
|
58
|
+
* import { loadRemoteModule } from '@nx/react/mf';
|
59
|
+
*
|
60
|
+
* loadRemoteModule('my-remote-app', './Module').then(m => m.RemoteEntryModule);
|
61
|
+
* ```
|
62
|
+
* change it to use loadRemote():
|
63
|
+
* ```ts
|
64
|
+
* import { loadRemote } from '@module-federation/enhanced/runtime';
|
65
|
+
*
|
66
|
+
* loadRemote<typeof import('my-remote-app/Module')>('my-remote-app/Module').then(m => m.RemoteEntryModule);
|
67
|
+
* ```
|
68
|
+
*/
|
5
69
|
export declare function loadRemoteModule(remoteName: string, moduleName: string): Promise<any>;
|
package/mf/dynamic-federation.js
CHANGED
@@ -9,15 +9,79 @@ let resolveRemoteUrl;
|
|
9
9
|
const remoteModuleMap = new Map();
|
10
10
|
const remoteContainerMap = new Map();
|
11
11
|
let initialSharingScopeCreated = false;
|
12
|
+
/**
|
13
|
+
* @deprecated Use Runtime Helpers from '@module-federation/enhanced/runtime' instead. This will be removed in Nx 22.
|
14
|
+
*/
|
12
15
|
function setRemoteUrlResolver(_resolveRemoteUrl) {
|
13
16
|
resolveRemoteUrl = _resolveRemoteUrl;
|
14
17
|
}
|
18
|
+
/**
|
19
|
+
* @deprecated Use init() from '@module-federation/enhanced/runtime' instead. This will be removed in Nx 22.
|
20
|
+
* If you have a remote app called `my-remote-app` and you want to use the `http://localhost:4201/mf-manifest.json` as the remote url, you should change it from:
|
21
|
+
* ```ts
|
22
|
+
* import { setRemoteDefinitions } from '@nx/react/mf';
|
23
|
+
*
|
24
|
+
* setRemoteDefinitions({
|
25
|
+
* 'my-remote-app': 'http://localhost:4201/mf-manifest.json'
|
26
|
+
* });
|
27
|
+
* ```
|
28
|
+
* to use init():
|
29
|
+
* ```ts
|
30
|
+
* import { init } from '@module-federation/enhanced/runtime';
|
31
|
+
*
|
32
|
+
* init({
|
33
|
+
* name: 'host',
|
34
|
+
* remotes: [{
|
35
|
+
* name: 'my-remote-app',
|
36
|
+
* entry: 'http://localhost:4201/mf-manifest.json'
|
37
|
+
* }]
|
38
|
+
* });
|
39
|
+
* ```
|
40
|
+
*/
|
15
41
|
function setRemoteDefinitions(definitions) {
|
16
42
|
remoteUrlDefinitions = definitions;
|
17
43
|
}
|
44
|
+
/**
|
45
|
+
* @deprecated Use registerRemotes() from '@module-federation/enhanced/runtime' instead. This will be removed in Nx 22.
|
46
|
+
* If you set a remote app with `setRemoteDefinition` such as:
|
47
|
+
* ```ts
|
48
|
+
* import { setRemoteDefinition } from '@nx/react/mf';
|
49
|
+
*
|
50
|
+
* setRemoteDefinition(
|
51
|
+
* 'my-remote-app',
|
52
|
+
* 'http://localhost:4201/mf-manifest.json'
|
53
|
+
* );
|
54
|
+
* ```
|
55
|
+
* change it to use registerRemotes():
|
56
|
+
* ```ts
|
57
|
+
* import { registerRemotes } from '@module-federation/enhanced/runtime';
|
58
|
+
*
|
59
|
+
* registerRemotes([
|
60
|
+
* {
|
61
|
+
* name: 'my-remote-app',
|
62
|
+
* entry: 'http://localhost:4201/mf-manifest.json'
|
63
|
+
* }
|
64
|
+
* ]);
|
65
|
+
* ```
|
66
|
+
*/
|
18
67
|
function setRemoteDefinition(remoteName, remoteUrl) {
|
19
68
|
remoteUrlDefinitions[remoteName] = remoteUrl;
|
20
69
|
}
|
70
|
+
/**
|
71
|
+
* @deprecated Use loadRemote() from '@module-federation/enhanced/runtime' instead. This will be removed in Nx 22.
|
72
|
+
* If you set a load a remote with `loadRemoteModule` such as:
|
73
|
+
* ```ts
|
74
|
+
* import { loadRemoteModule } from '@nx/react/mf';
|
75
|
+
*
|
76
|
+
* loadRemoteModule('my-remote-app', './Module').then(m => m.RemoteEntryModule);
|
77
|
+
* ```
|
78
|
+
* change it to use loadRemote():
|
79
|
+
* ```ts
|
80
|
+
* import { loadRemote } from '@module-federation/enhanced/runtime';
|
81
|
+
*
|
82
|
+
* loadRemote<typeof import('my-remote-app/Module')>('my-remote-app/Module').then(m => m.RemoteEntryModule);
|
83
|
+
* ```
|
84
|
+
*/
|
21
85
|
async function loadRemoteModule(remoteName, moduleName) {
|
22
86
|
const remoteModuleKey = `${remoteName}:${moduleName}`;
|
23
87
|
if (remoteModuleMap.has(remoteModuleKey)) {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nx/react",
|
3
|
-
"version": "20.1.0-canary.
|
3
|
+
"version": "20.1.0-canary.20241102-c290b37",
|
4
4
|
"private": false,
|
5
5
|
"description": "The React plugin for Nx contains executors and generators for managing React applications and libraries within an Nx workspace. It provides:\n\n\n- Integration with libraries such as Jest, Vitest, Playwright, Cypress, and Storybook.\n\n- Generators for applications, libraries, components, hooks, and more.\n\n- Library build support for publishing packages to npm or other registries.\n\n- Utilities for automatic workspace refactoring.",
|
6
6
|
"repository": {
|
@@ -39,10 +39,10 @@
|
|
39
39
|
"picocolors": "^1.1.0",
|
40
40
|
"tslib": "^2.3.0",
|
41
41
|
"@module-federation/enhanced": "0.6.9",
|
42
|
-
"@nx/devkit": "20.1.0-canary.
|
43
|
-
"@nx/js": "20.1.0-canary.
|
44
|
-
"@nx/eslint": "20.1.0-canary.
|
45
|
-
"@nx/web": "20.1.0-canary.
|
42
|
+
"@nx/devkit": "20.1.0-canary.20241102-c290b37",
|
43
|
+
"@nx/js": "20.1.0-canary.20241102-c290b37",
|
44
|
+
"@nx/eslint": "20.1.0-canary.20241102-c290b37",
|
45
|
+
"@nx/web": "20.1.0-canary.20241102-c290b37",
|
46
46
|
"express": "^4.19.2",
|
47
47
|
"http-proxy-middleware": "^3.0.3"
|
48
48
|
},
|
@@ -1,9 +1,10 @@
|
|
1
1
|
<%_ if (strict) { _%>import { StrictMode } from 'react';<%_ } _%>
|
2
2
|
import * as ReactDOM from 'react-dom/client';
|
3
3
|
<%_ if (routing) { _%>import { BrowserRouter } from 'react-router-dom';<%_ } _%>
|
4
|
-
|
5
4
|
import App from './app/<%= fileName %>';
|
6
|
-
|
5
|
+
<%_ if(hasStyleFile) { _%>
|
6
|
+
import './styles.<%= style %>'
|
7
|
+
<%_ } _%>
|
7
8
|
|
8
9
|
const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
|
9
10
|
<%_ if(strict && !routing) { _%>
|
@@ -30,6 +30,7 @@ async function createApplicationFiles(host, options) {
|
|
30
30
|
else {
|
31
31
|
styleSolutionSpecificAppFiles = '../files/style-css-module';
|
32
32
|
}
|
33
|
+
const hasStyleFile = ['scss', 'css', 'less'].includes(options.style);
|
33
34
|
const onBoardingStatus = await (0, onboarding_1.createNxCloudOnboardingURLForWelcomeApp)(host, options.nxCloudToken);
|
34
35
|
const connectCloudUrl = onBoardingStatus === 'unclaimed' &&
|
35
36
|
(await (0, onboarding_1.getNxCloudAppOnBoardingUrl)(options.nxCloudToken));
|
@@ -44,6 +45,7 @@ async function createApplicationFiles(host, options) {
|
|
44
45
|
appTests,
|
45
46
|
inSourceVitestTests: (0, get_in_source_vitest_tests_template_1.getInSourceVitestTestsTemplate)(appTests),
|
46
47
|
style: options.style === 'tailwind' ? 'css' : options.style,
|
48
|
+
hasStyleFile,
|
47
49
|
};
|
48
50
|
if (options.bundler === 'vite') {
|
49
51
|
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/base-vite'), options.appProjectRoot, templateVariables);
|
@@ -3,12 +3,19 @@ import * as React from 'react';
|
|
3
3
|
import NxWelcome from "./nx-welcome";
|
4
4
|
<%_ } _%>
|
5
5
|
import { Link, Route, Routes } from 'react-router-dom';
|
6
|
+
<%_ if (dynamic) { _%>
|
7
|
+
import { loadRemote } from '@module-federation/enhanced/runtime';
|
8
|
+
<%_ } _%>
|
6
9
|
|
7
10
|
<%_ if (remotes.length > 0) {
|
8
|
-
|
11
|
+
remotes.forEach(function(r) { _%>
|
12
|
+
<%_ if (dynamic) { _%>
|
13
|
+
const <%= r.className %> = React.lazy(() => loadRemote('<%= r.fileName %>/Module') as any)
|
14
|
+
<%_ } else { _%>
|
9
15
|
const <%= r.className %> = React.lazy(() => import('<%= r.fileName %>/Module'));
|
10
|
-
<%_ }
|
11
|
-
<% } %>
|
16
|
+
<%_ } _%>
|
17
|
+
<%_ }); _%>
|
18
|
+
<%_ } _%>
|
12
19
|
export function App() {
|
13
20
|
return (
|
14
21
|
<React.Suspense fallback={null}>
|
@@ -1,10 +1,13 @@
|
|
1
1
|
<%_ if (dynamic) { _%>
|
2
|
-
import {
|
2
|
+
import { init } from '@module-federation/enhanced/runtime';
|
3
3
|
|
4
4
|
fetch('/assets/module-federation.manifest.json')
|
5
5
|
.then((res) => res.json())
|
6
|
-
.then(
|
6
|
+
.then((remotes: Record<string, string>) =>
|
7
|
+
Object.entries(remotes).map(([name, entry]) => ({ name, entry }))
|
8
|
+
)
|
9
|
+
.then((remotes) => init({ name: '<%= projectName %>', remotes }))
|
7
10
|
.then(() => import('./bootstrap').catch(err => console.error(err)));
|
8
11
|
<%_ } else { _%>
|
9
12
|
import('./bootstrap').catch(err => console.error(err));
|
10
|
-
<%_ } _%>
|
13
|
+
<%_ } _%>
|
@@ -4,17 +4,17 @@ import NxWelcome from "./nx-welcome";
|
|
4
4
|
<%_ } _%>
|
5
5
|
import { Link, Route, Routes } from 'react-router-dom';
|
6
6
|
<%_ if (dynamic) { _%>
|
7
|
-
import {
|
7
|
+
import { loadRemote } from '@module-federation/enhanced/runtime';
|
8
8
|
<%_ } _%>
|
9
9
|
|
10
10
|
<%_ if (remotes.length > 0) {
|
11
|
-
|
12
|
-
|
13
|
-
const <%= r.className %> = React.lazy(() =>
|
14
|
-
|
11
|
+
remotes.forEach(function(r) { _%>
|
12
|
+
<%_ if (dynamic) { _%>
|
13
|
+
const <%= r.className %> = React.lazy(() => loadRemote('<%= r.fileName %>/Module') as any)
|
14
|
+
<%_ } else { _%>
|
15
15
|
const <%= r.className %> = React.lazy(() => import('<%= r.fileName %>/Module'));
|
16
|
-
|
17
|
-
|
16
|
+
<%_ } _%>
|
17
|
+
<%_ }); _%>
|
18
18
|
<%_ } _%>
|
19
19
|
|
20
20
|
export function App() {
|
@@ -1,10 +1,13 @@
|
|
1
1
|
<%_ if (dynamic) { _%>
|
2
|
-
import {
|
2
|
+
import { init } from '@module-federation/enhanced/runtime';
|
3
3
|
|
4
4
|
fetch('/assets/module-federation.manifest.json')
|
5
5
|
.then((res) => res.json())
|
6
|
-
.then(
|
7
|
-
.
|
6
|
+
.then((remotes: Record<string, string>) =>
|
7
|
+
Object.entries(remotes).map(([name, entry]) => ({ name, entry }))
|
8
|
+
)
|
9
|
+
.then((remotes) => init({ name: '<%= projectName %>', remotes }))
|
10
|
+
.then(() => import('./bootstrap').catch(err => console.error(err)));
|
8
11
|
<%_ } else { _%>
|
9
12
|
import('./bootstrap').catch(err => console.error(err));
|
10
|
-
<%_ } _%>
|
13
|
+
<%_ } _%>
|
@@ -4,11 +4,20 @@ import NxWelcome from "./nx-welcome";
|
|
4
4
|
<%_ } _%>
|
5
5
|
import { Link, Route, Routes } from 'react-router-dom';
|
6
6
|
|
7
|
-
<% if (
|
8
|
-
|
7
|
+
<%_ if (dynamic) { _%>
|
8
|
+
import { loadRemote } from '@module-federation/enhanced/runtime';
|
9
|
+
<%_ } _%>
|
10
|
+
|
11
|
+
<%_ if (remotes.length > 0) {
|
12
|
+
remotes.forEach(function(r) { _%>
|
13
|
+
<%_ if (dynamic) { _%>
|
14
|
+
const <%= r.className %> = React.lazy(() => loadRemote('<%= r.fileName %>/Module') as any)
|
15
|
+
<%_ } else { _%>
|
9
16
|
const <%= r.className %> = React.lazy(() => import('<%= r.fileName %>/Module'));
|
10
|
-
<%_ }); _%>
|
11
17
|
<%_ } _%>
|
18
|
+
<%_ }); _%>
|
19
|
+
<%_ } _%>
|
20
|
+
|
12
21
|
export function App() {
|
13
22
|
return (
|
14
23
|
<React.Suspense fallback={null}>
|
@@ -1,10 +1,13 @@
|
|
1
1
|
<%_ if (dynamic) { _%>
|
2
|
-
import {
|
2
|
+
import { init } from '@module-federation/enhanced/runtime';
|
3
3
|
|
4
4
|
fetch('/assets/module-federation.manifest.json')
|
5
5
|
.then((res) => res.json())
|
6
|
-
.then(
|
6
|
+
.then((remotes: Record<string, string>) =>
|
7
|
+
Object.entries(remotes).map(([name, entry]) => ({ name, entry }))
|
8
|
+
)
|
9
|
+
.then((remotes) => init({ name: '<%= projectName %>', remotes }))
|
7
10
|
.then(() => import('./bootstrap').catch(err => console.error(err)));
|
8
11
|
<%_ } else { _%>
|
9
12
|
import('./bootstrap').catch(err => console.error(err));
|
10
|
-
<%_ } _%>
|
13
|
+
<%_ } _%>
|
@@ -104,7 +104,9 @@ async function hostGenerator(host, schema) {
|
|
104
104
|
host.delete((0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.lint.json'));
|
105
105
|
}
|
106
106
|
(0, add_mf_env_to_inputs_1.addMfEnvToTargetDefaultInputs)(host);
|
107
|
-
const installTask = (0, devkit_1.addDependenciesToPackageJson)(host, {
|
107
|
+
const installTask = (0, devkit_1.addDependenciesToPackageJson)(host, { '@module-federation/enhanced': versions_1.moduleFederationEnhancedVersion }, {
|
108
|
+
'@nx/web': versions_1.nxVersion,
|
109
|
+
});
|
108
110
|
tasks.push(installTask);
|
109
111
|
if (!options.skipFormat) {
|
110
112
|
await (0, devkit_1.formatFiles)(host);
|
@@ -59,7 +59,7 @@ function addModuleFederationFiles(host, options, defaultRemoteManifest) {
|
|
59
59
|
if (!host.exists(pathToMFManifest)) {
|
60
60
|
host.write(pathToMFManifest, `{
|
61
61
|
${defaultRemoteManifest
|
62
|
-
.map(({ name, port }) => `"${name}": "http://localhost:${port}"`)
|
62
|
+
.map(({ name, port }) => `"${name}": "http://localhost:${port}/mf-manifest.json"`)
|
63
63
|
.join(',\n')}
|
64
64
|
}`);
|
65
65
|
}
|