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
### Exposing Web Component with other Frameworks like Ract
71
+
72
+
If you framework doesn't directly support exposing your application as a web component, you can easily write a simple Wrapper around it. Basically, a web component -- to be more precise: a custom element -- is just an EcmaScript class extending ``HtmlElement`` and registered via ``customElements.register``. Please find an [example for React here](https://github.com/manfredsteyer/react-app/blob/main/app.js).
73
+
74
+
### Exposting Web Component-based Micro Frontend via Module Federation
75
+
59
76
Add ``@angular-architects/module-federation`` to your micro frontend:
60
77
61
78
```
@@ -74,9 +91,12 @@ exposes: {
74
91
},
75
92
```
76
93
77
-
## Bootstrapping
94
+
If the file that bootstraps your applications is called differently, adjust these settings accordingly.
95
+
96
+
## Helper for Angular
97
+
98
+
For enabling Angular for a multi version/ multi framework scenario, we need some helper functions. The easiest way to use them, is to bootstrap your Angular app with our bootstrap helper:
78
99
79
-
Our ``bootstrap`` helper function bootstraps your shell and your micro frontend and takes care of some details needed in a multi-framework/ multi-version scenario (like sharing the ``platform`` used).
80
100
81
101
```typescript
82
102
// main.ts
@@ -85,71 +105,15 @@ import { environment } from './environments/environment';
The micro frontends will pick it up, if they are bootstrapped with the ``bootstrap`` helper (see above).
117
-
118
-
## Details on ngZone and Platform sharing
119
-
120
-
> In a multi version micro frontend strategy, it is important to load the zone.js bundle to the window object only once. Also, one need to make sure that only one instance of the ngZone is used by all the micro frontends.
121
-
122
-
If you share `@angular/core` and therefore also have one technical reference to the BrowserPlatform, that is used by more than one micro frondend, Angular's default setup is, to support only one platform instance per shared version. Be aware that you **need** to create multi platform instances in case of different versions, but also in case the version is the same, but `@angular/core` is not shared, but packed into the micro frontend's bundles directly (like in Angular's default way w/o module federation).
123
-
124
-
Naturally, such technical details are hard to get into. Therefore the `bootstrap()` function of this package helps to implement your multi version strategy w/o the need of implementing those low-level aspects on your own.
125
-
126
-
Some optional flags are offered to provide options for custom behavior of the `bootstrap()` function:
127
-
128
-
-`ngZoneSharing: false`: Deactivate ngZone sharing in the window object (not recommended):
129
-
```typescript
130
-
bootstrap(AppModule, {
131
-
production: environment.production,
132
-
ngZoneSharing: false// defaults to true
133
-
});
134
-
```
135
-
-`platformSharing: false`: Deactivate Platform sharing in the window object (not recommended):
136
-
```typescript
137
-
bootstrap(AppModule, {
138
-
production: environment.production,
139
-
platformSharing: false// defaults to true
140
-
});
141
-
```
142
-
- Possible, if dependencies are not shared or each bootstrapped remote app uses a different version.
143
-
-`activeLegacyMode: false`: Deactivates the legacy mode that provides backwards compatibility for Platform sharing:
144
-
```typescript
145
-
bootstrap(AppModule, {
146
-
production: environment.production,
147
-
activeLegacyMode: false// defaults to true
148
-
});
149
-
```
150
-
- If all your micro frontends use `@angular-architects/module-federation-tools` in version `^12.6.0`, `^13.1.0` or any newer major version you can switch off the legacy mode manually.
151
-
- Those versions introduced new features on how to share the Platform in the window object.
152
-
- This allows to use the `bootstrap()` function even in such cases, where the same version is packed into different micro frontend bundles.
116
+
Please make sure to set the ``appType`` to ``shell`` for your shell application and to ``microfrontend`` for your Micro Frontends.
> In a multi version micro frontend strategy, it is important to load the zone.js bundle to the window object only once. Also, one need to make sure that only one instance of the ngZone is used by all the micro frontends.
234
+
235
+
If you share `@angular/core` and therefore also have one technical reference to the BrowserPlatform, that is used by more than one micro frondend, Angular's default setup is, to support only one platform instance per shared version. Be aware that you **need** to create multi platform instances in case of different versions, but also in case the version is the same, but `@angular/core` is not shared, but packed into the micro frontend's bundles directly (like in Angular's default way w/o module federation).
236
+
237
+
Naturally, such technical details are hard to get into. Therefore the `bootstrap()` function of this package helps to implement your multi version strategy w/o the need of implementing those low-level aspects on your own.
238
+
239
+
Some optional flags are offered to provide options for custom behavior of the `bootstrap()` function:
240
+
241
+
- `ngZoneSharing: false`: Deactivate ngZone sharing in the window object (not recommended):
242
+
```typescript
243
+
bootstrap(AppModule, {
244
+
production: environment.production,
245
+
ngZoneSharing: false// defaults to true
246
+
});
247
+
```
248
+
- `platformSharing: false`: Deactivate Platform sharing in the window object (not recommended):
249
+
```typescript
250
+
bootstrap(AppModule, {
251
+
production: environment.production,
252
+
platformSharing: false// defaults to true
253
+
});
254
+
```
255
+
- Possible, if dependencies are not shared or each bootstrapped remote app uses a different version.
256
+
- `activeLegacyMode: false`: Deactivates the legacy mode that provides backwards compatibility for Platform sharing:
257
+
```typescript
258
+
bootstrap(AppModule, {
259
+
production: environment.production,
260
+
activeLegacyMode: false// defaults to true
261
+
});
262
+
```
263
+
- If all your micro frontends use `@angular-architects/module-federation-tools` in version `^12.6.0`, `^13.1.0` or any newer major version you can switch off the legacy mode manually.
264
+
- Those versions introduced new features on how to share the Platform in the window object.
265
+
- This allows to use the `bootstrap()` function even in such cases, where the same version is packed into different micro frontend bundles.
266
+
267
+
268
+
280
269
## More about the underlying ideas
281
270
282
271
Please find more information on the underlying ideas in this [blog article](https://www.angulararchitects.io/aktuelles/multi-framework-and-version-micro-frontends-with-module-federation-the-good-the-bad-the-ugly).
0 commit comments