Skip to content

Commit 02126be

Browse files
Update README.md, cleanuo.
1 parent f67a331 commit 02126be

1 file changed

Lines changed: 47 additions & 41 deletions

File tree

README.md

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This is a sample project for using MFEs with an Angular host and a React remote, using Nx.
44

5-
All code is provided in the GitHub repo [mfe-angular-react-nx](https://github.com/angularexample/mfe-angular-react-nx).
5+
All code is provided in the GitHub repo [https://github.com/angularexample/mfe-angular-react-nx](https://github.com/angularexample/mfe-angular-react-nx).
66

77
It includes step-by-step instructions for creating the project.
88

@@ -14,13 +14,13 @@ August 22, 2025
1414

1515
At the time of this writing, it used the latest versions provided by Nx
1616

17-
* Nx 21.4.1
1817
* Angular 20.1.0
1918
* React 19.0.0
19+
* Nx 21.4.1
2020

2121
## About The Author
2222

23-
```JC Lango``` is a UI Architect and Developer for many large-scale web applications at several well-known Fortune 500 companies.
23+
`JC Lango` is a UI Architect and Developer for many large-scale web applications at several well-known Fortune 500 companies.
2424

2525
He is an expert in **Angular** and **React** and maintains these sites at GitHub:
2626

@@ -69,10 +69,10 @@ Open a terminal window, go to the base directory where you want the new workspac
6969
npx create-nx-workspace mfe-angular-react-nx --preset=apps
7070
```
7171

72-
This will create a new Nx workspace in the directory ```mfe-angular-react-nx```.
72+
This will create a new Nx workspace in the directory `mfe-angular-react-nx`.
7373

74-
* The name of the project or workspace in this case is ```mfe-angular-react-nx```.
75-
* The option ```--preset=apps``` will create an empty workspace with no app or framework.
74+
* The name of the project or workspace in this case is `mfe-angular-react-nx`.
75+
* The option `--preset=apps` will create an empty workspace with no app or framework.
7676

7777
When prompted, select the following options.
7878

@@ -87,9 +87,13 @@ Using your IDE, open the workspace.
8787

8888
The rest of the instructions will be done in your IDE.
8989

90+
In your IDE, Open a terminal window and ensure the location is the root of the workspace.
91+
92+
Use the IDE terminal to run all the commands in this project.
93+
9094
### Create a Git Repository
9195

92-
If you use the option for ```GitHub Actions``` when creating the workspace,
96+
If you use the option for `GitHub Actions` when creating the workspace,
9397
a local Git repository will automatically be created in the workspace directory.
9498
In that case, you can skip this step to create a Git repository.
9599

@@ -99,13 +103,14 @@ Note: Alternatively, share the project on GitHub. This will create a new reposit
99103

100104
### Add the error.log Directory to the .gitignore File
101105

102-
Use your IDE to add the ```error.log``` directory to the .gitignore file.
106+
Use your IDE to add the `error.log` directory to the .gitignore file.
103107

104-
In your IDE, Open a terminal window and ensure the location is the root of the workspace.
108+
## Add Nx Packages for Angular and React
105109

106-
Use the IDE terminal to run all the commands in this project.
110+
You need the Nx packages for Angular and React.
111+
112+
Note: The old packages: `@nrwl/angular`, `@nrwl/react` are deprecated.
107113

108-
## Add Nx Packages for Angular and React
109114

110115
### Add the Nx Package for Angular
111116

@@ -138,6 +143,7 @@ Add the following command line options.
138143
```
139144
nx g @nx/angular:host apps/host --dynamic --remotes=remote1,remote2 --style=scss --e2eTestRunner=playwright --unitTestRunner=jest
140145
```
146+
141147
NOTE: The --remotes option is a comma-separated list of remote applications.
142148
When using the Angular host generator, the remote applications will always be Angular applications.
143149

@@ -183,11 +189,10 @@ It will have a menu in the upper left corner.
183189
In this case, if you have generated a host and two remotes,
184190
the menu will have three items:
185191

186-
```
192+
187193
* Home
188194
* Remote1
189195
* Remote2
190-
```
191196

192197
#### Use the Menu to Access the Remote Applications
193198

@@ -205,9 +210,9 @@ For example, the Remote1 application will be:
205210
http://localhost:4200/remote1
206211
```
207212

208-
When you click on the ```Remote1``` menu item, you should see the remote application running in the browser.
213+
When you click on the `Remote1` menu item, you should see the remote application running in the browser.
209214

210-
When you click on the ```Remote2``` menu item, you should see the remote application running in the browser.
215+
When you click on the `Remote2` menu item, you should see the remote application running in the browser.
211216

212217
#### Verify the Remote View is Provided by MFE
213218

@@ -219,17 +224,17 @@ Refresh the browser.
219224
For each remote page that you visit, you should see a request for each of the remote applications.
220225

221226
For example, for the view at
222-
```http://localhost:4200/remote1/```
227+
`http://localhost:4200/remote1/`
223228
the request is:
224229

225-
```http://localhost:4201/default-apps_remote1_src_app_remote-entry_entry_ts.js```
230+
`http://localhost:4201/default-apps_remote1_src_app_remote-entry_entry_ts.js`
226231

227232
Webpack bundles the remote app as a single JavaScript file, and the remote application is served from its own server address.
228233
The remote app is accessed as a script request by the host application.
229234

230235
The request URL for the second remote application is:
231236

232-
```http://localhost:4202/default-apps_remote2_src_app_remote-entry_entry_ts.js```
237+
`http://localhost:4202/default-apps_remote2_src_app_remote-entry_entry_ts.js`
233238

234239
* In this case, **4202** is the port address for the second remote application.
235240

@@ -243,29 +248,30 @@ If you want to create a React remote application, you will need to use the Nx Re
243248

244249
Generate the React remote application using the @nx/react package.
245250

251+
```
252+
nx g @nx/react:remote apps/remote3 --style=scss --e2eTestRunner=playwright --bundler=webpack
253+
```
254+
246255
See the Nx documentation for more information on the [React Remote App Generator Options](https://nx.dev/technologies/react/api/generators/remote#options)
247256

248-
Add the following command line options.
257+
We are using the following command line options:
249258

250259
* --style=scss
251260
* --e2eTestRunner=playwright
252261
* --bundler=webpack
253262

254263
If you provide a path name for the remote application, you don't need the name or directory options.
255264

256-
In this case, ```remote3``` is the name, and ```apps``` is the directory.
265+
In this case, `remote3` is the name, and `apps` is the directory.
257266

258-
**NOTE: Do not supply the ```--host``` option.**
267+
**NOTE: Do not supply the `--host` option.**
259268

260269
Since the host is an Angular application, the generation step will fail.
261270
The Nx generator does not support mixing different frameworks in MFEs.
262271

263272
You will need to configure the remote application to the host manually.
264273
We will provide detailed instructions later in this document.
265274

266-
```
267-
nx g @nx/react:remote apps/remote3 --style=scss --e2eTestRunner=playwright --bundler=webpack
268-
```
269275

270276
### Build and Run the Remote Application
271277

@@ -312,7 +318,7 @@ There are several steps to manually add the React remote application to the Angu
312318

313319
Open the host manifest file.
314320

315-
```apps/host/public/module-federation.manifest.json```
321+
`apps/host/public/module-federation.manifest.json`
316322

317323
BEFORE
318324
```json
@@ -354,19 +360,19 @@ It can only be used with React 18 or newer.
354360

355361
Open the React remote app component.
356362

357-
```apps/remote3/src/app/app.tsx```
363+
`apps/remote3/src/app/app.tsx`
358364

359-
Import the ```r2wc``` function from the package.
365+
Import the `r2wc` function from the package.
360366

361367
```typescript
362368
import r2wc from '@r2wc/react-to-web-component';
363369
```
364370

365-
In your React component, after the ```App()``` function,
371+
In your React component, after the `App()` function,
366372
add a function to convert the component to a Web Component.
367373

368374
You will need to supply a new element name for the Web Component.
369-
In this case, we will use the name ```wc-remote3```.
375+
In this case, we will use the name `wc-remote3`.
370376

371377
```typescript
372378
export function defineReactWebComponent() {
@@ -391,7 +397,7 @@ export default App;
391397

392398
We need an Angular component to wrap the React Web Component.
393399

394-
We will call this component ```react-wrapper```.
400+
We will call this component `react-wrapper`.
395401

396402
In the Angular host app, create a new directory using the same name as the component, in the src/app directory, and create the component, using the Nx Angular component generator.
397403

@@ -401,17 +407,17 @@ nx g @nx/angular:component apps/host/src/app/react-wrapper/react-wrapper
401407

402408
Open the wrapper component.
403409

404-
```apps/host/src/app/react-wrapper/react-wrapper.ts```
410+
`apps/host/src/app/react-wrapper/react-wrapper.ts`
405411

406-
Remove the ```templateUrl``` and ```styleUrl``` properties.
412+
Remove the `templateUrl` and `styleUrl` properties.
407413

408414
Delete those two files.
409415

410-
```apps/host/src/app/react-wrapper/react-wrapper.css```
416+
`apps/host/src/app/react-wrapper/react-wrapper.css`
411417

412-
```apps/host/src/app/react-wrapper/react-wrapper.html```
418+
`apps/host/src/app/react-wrapper/react-wrapper.html`
413419

414-
Remove the import for the ```CommonModule```.
420+
Remove the import for the `CommonModule`.
415421

416422
BEFORE
417423
```typescript
@@ -454,7 +460,7 @@ export class ReactWrapper implements AfterContentInit {
454460

455461
This wrapper component will load the React Web Component into the view.
456462

457-
It gets the loader function, ```loadchildren``` from the route data.
463+
It gets the loader function, `loadchildren` from the route data.
458464

459465
It gets the name of the Web Component from the route data.
460466

@@ -464,15 +470,15 @@ Then it creates a new element and inserts the React Web Component into it.
464470

465471
Open the host routes file.
466472

467-
```apps/host/src/app/app.routes.ts```
473+
`apps/host/src/app/app.routes.ts`
468474

469475
Import the wrapper component.
470476

471477
```typescript
472478
import { ReactWrapper } from './react-wrapper/react-wrapper';
473479
```
474480

475-
Add a new route by adding the following code to the ```app.routes.ts``` file.
481+
Add a new route by adding the following code to the `app.routes.ts` file.
476482

477483
```
478484
{
@@ -492,7 +498,7 @@ Add a new route by adding the following code to the ```app.routes.ts``` file.
492498

493499
Open the host tsconfig.json file.
494500

495-
```apps/host/tsconfig.json```
501+
`apps/host/tsconfig.json`
496502

497503
Under the compilerOptions, add the following code to allow JSX.
498504

@@ -505,7 +511,7 @@ Under the compilerOptions, add the following code to allow JSX.
505511

506512
Open the host app.html file.
507513

508-
```apps/host/src/app/app.html```
514+
`apps/host/src/app/app.html`
509515

510516
Add the following code to the host app.html file.
511517

@@ -522,6 +528,6 @@ After clicking on the navigation link, you should see the React remote applicati
522528
When using the Nx generator to create the host and remote applications,
523529
it will automatically use the Nx Welcome page component for each of the view components.
524530

525-
```apps/host/src/app/nx-welcome.ts```
531+
`apps/host/src/app/nx-welcome.ts`
526532

527533
Once you have generated the host and remote MFE apps, you can replace the default welcome page component with your own component.

0 commit comments

Comments
 (0)