You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*[Update the React Remote to Convert to a Web Component](#update-the-react-remote-to-convert-to-a-web-component)
55
56
*[In the Angular Host, Add a Wrapper Component](#in-the-angular-host-add-a-wrapper-component)
56
57
*[Add the Wrapper Component and the React Remote Component to the Host Routes](#add-the-wrapper-component-and-the-react-remote-component-to-the-host-routes)
57
58
*[Add Jsx to the Host TsConfig](#add-jsx-to-the-host-tsconfig)
59
+
*[Add the React Remote to the Host Manifest](#add-the-react-remote-to-the-host-manifest)
58
60
*[Add the React Remote URL to the Host HTML](#add-the-react-remote-url-to-the-host-html)
59
61
*[ReRun the Host Application To Verify the React Remote Application](#rerun-the-host-application-to-verify-the-react-remote-application)
60
62
*[Next Steps](#next-steps)
@@ -128,23 +130,23 @@ Commit and push the changes.
128
130
129
131
## Generate the Angular Host App and Two Remotes
130
132
131
-
Use the Nx Angular Generator command to create the Angular host app.
133
+
Use the Nx Angular Generator in `@nx/angular` to create the Angular host app with this command:
134
+
135
+
```
136
+
nx g @nx/angular:host apps/host --dynamic --remotes=remote1,remote2 --style=scss --e2eTestRunner=playwright --unitTestRunner=jest
137
+
```
132
138
133
139
See the Nx documentation for more information on the [Angular Host App Generator Options](https://nx.dev/technologies/angular/api/generators/host#options)
134
140
135
-
Add the following command line options.
141
+
We are using the following command line options.
136
142
137
143
* --dynamic
138
144
* --remotes=remote1,remote2
139
145
* --style=scss
140
146
* --e2eTestRunner=playwright
141
147
* --unitTestRunner=jest
142
148
143
-
```
144
-
nx g @nx/angular:host apps/host --dynamic --remotes=remote1,remote2 --style=scss --e2eTestRunner=playwright --unitTestRunner=jest
145
-
```
146
-
147
-
NOTE: The --remotes option is a comma-separated list of remote applications.
149
+
**NOTE:** The --remotes option is a comma-separated list of remote applications.
148
150
When using the Angular host generator, the remote applications will always be Angular applications.
149
151
150
152
### Commit and Push the Changes for the Angular Host App
@@ -168,7 +170,7 @@ Or you can use a command in the terminal window.
168
170
nx run host:serve:development
169
171
```
170
172
171
-
***host** is the name of the host application.
173
+
In this example, `host` is the name of the host application.
172
174
173
175
In the Run console output, it should include the browser address.
174
176
@@ -189,22 +191,21 @@ It will have a menu in the upper left corner.
189
191
In this case, if you have generated a host and two remotes,
190
192
the menu will have three items:
191
193
192
-
193
194
* Home
194
195
* Remote1
195
196
* Remote2
196
197
197
-
####Use the Menu to Access the Remote Applications
198
+
### Use the Menu to Access the Remote Applications
198
199
199
-
Try clicking on the **Remote1** or **Remote2** menu items.
200
+
Try clicking on the `Remote1` or `Remote2` menu items.
200
201
201
202
You will see that each remote is accessed with routing.
202
203
203
204
The host application will be the root.
204
205
Each remote will be a child of the host application.
205
206
206
207
The remote app name will be in the URL path.
207
-
For example, the Remote1 application will be:
208
+
For example, the `Remote1` application URL will be:
208
209
209
210
```
210
211
http://localhost:4200/remote1
@@ -217,7 +218,7 @@ When you click on the `Remote2` menu item, you should see the remote application
217
218
#### Verify the Remote View is Provided by MFE
218
219
219
220
To verify that the remote view is provided by MFE,
220
-
open the browser Developer Tools and go to the **Network** tab.
221
+
open the browser Developer Tools and go to the `Network` tab.
221
222
222
223
Refresh the browser.
223
224
@@ -246,7 +247,7 @@ As noted earlier, the Angular host generator will always create Angular applicat
246
247
247
248
If you want to create a React remote application, you will need to use the Nx React Remote App Generator.
248
249
249
-
Generate the React remote application using the @nx/react package.
250
+
Generate the React remote application using the `@nx/react` package with this command:
250
251
251
252
```
252
253
nx g @nx/react:remote apps/remote3 --style=scss --e2eTestRunner=playwright --bundler=webpack
@@ -272,7 +273,6 @@ The Nx generator does not support mixing different frameworks in MFEs.
272
273
You will need to configure the remote application to the host manually.
273
274
We will provide detailed instructions later in this document.
274
275
275
-
276
276
### Build and Run the Remote Application
277
277
278
278
Build and run the remote application and test it in the browser.
@@ -285,7 +285,7 @@ Or you can use a command in the terminal window.
285
285
nx run remote3:serve:development
286
286
```
287
287
288
-
***Remote3** is the name of the React remote application.
288
+
In this example, `*remote3` is the name of the React remote application.
289
289
290
290
Look in the Run console output for the browser address.
291
291
In this case, it is:
@@ -314,39 +314,16 @@ You will need to configure the remote application to the host manually.
314
314
315
315
There are several steps to manually add the React remote application to the Angular host.
To use the React remote application in the Angular host,
343
320
it must be converted to a Web Component.
344
321
345
-
We will use the **@r2wc/react-to-web-component** package to convert the React remote application to a Web Component.
322
+
We will use the `@r2wc/react-to-web-component` package to convert the React remote application to a Web Component.
346
323
347
-
####Add Package @r2wc/react-to-web-component
324
+
### Add Package @r2wc/react-to-web-component
348
325
349
-
Add the package **@r2wc/react-to-web-component** to the Nx workspace.
326
+
Add the package `@r2wc/react-to-web-component` to the Nx workspace.
350
327
351
328
```
352
329
nx add @r2wc/react-to-web-component
@@ -356,7 +333,7 @@ This package will convert a React component to a Web Component.
356
333
357
334
It can only be used with React 18 or newer.
358
335
359
-
####Update the React Remote to Convert to a Web Component
336
+
### Update the React Remote to Convert to a Web Component
360
337
361
338
Open the React remote app component.
362
339
@@ -399,7 +376,8 @@ We need an Angular component to wrap the React Web Component.
399
376
400
377
We will call this component `react-wrapper`.
401
378
402
-
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.
379
+
In the Angular host app, create a new directory using the same name as the component,
380
+
in the src/app directory, and create the component, using the Nx Angular component generator.
403
381
404
382
```
405
383
nx g @nx/angular:component apps/host/src/app/react-wrapper/react-wrapper
@@ -460,9 +438,9 @@ export class ReactWrapper implements AfterContentInit {
460
438
461
439
This wrapper component will load the React Web Component into the view.
462
440
463
-
It gets the loader function, `loadchildren` from the route data.
441
+
It gets the loader function, `load()` from the route data`loadChildren` property.
464
442
465
-
It gets the name of the Web Component from the route data.
443
+
It gets the name of the Web Component from the route data`elementName` property.`
466
444
467
445
Then it creates a new element and inserts the React Web Component into it.
468
446
@@ -507,6 +485,29 @@ Under the compilerOptions, add the following code to allow JSX.
0 commit comments