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
Copy file name to clipboardExpand all lines: packages/mf/README.md
+156-9Lines changed: 156 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@ Big thanks to the following people who helped to make this possible:
15
15
16
16
## Motivation 💥
17
17
18
-
Module Federation allows to load separately compiled and deployed code (like micro frontends or plugins) into an application. This plugin makes Module Federation work together with Angular and the CLI.
18
+
Module Federation allows loading separately compiled and deployed code (like micro frontends or plugins) into an application. This plugin makes Module Federation work together with Angular and the CLI.
19
19
20
20
## Features 🔥
21
21
@@ -27,13 +27,20 @@ Module Federation allows to load separately compiled and deployed code (like mic
27
27
28
28
The module federation config is a **partial** webpack configuration. It only contains stuff to control module federation. The rest is generated by the CLI as usual.
29
29
30
+
Since Version 1.2, we also provide some advanced features like:
@@ -49,7 +56,19 @@ The module federation config is a **partial** webpack configuration. It only con
49
56
50
57
- Run **yarn** to install all packages
51
58
52
-
Please that the CLI's webpack 5 support is current experimental.
59
+
Please that the CLI's webpack 5 support is experimental in CLI 11. Here, you find a list with [unresolved issues](https://github.com/angular/angular-cli/pull/18873) in the current version.
60
+
61
+
## Getting Started 🧪
62
+
63
+
Please find here a [tutorial](https://github.com/angular-architects/module-federation-plugin/blob/main/packages/mf/tutorial/tutorial.md) that shows how to use this plugin.
64
+
65
+

Please have a look at this [article series about Module Federation](https://www.angulararchitects.io/aktuelles/the-microfrontend-revolution-part-2-module-federation-with-angular/).
53
72
54
73
## Example 📽️
55
74
@@ -61,18 +80,146 @@ This [example](https://github.com/manfredsteyer/module-federation-plugin-example
61
80
Please have a look into the example's **readme**. It points you to the important aspects of using Module Federation.
62
81
63
82
64
-
## Tutorial 🧪
83
+
## Advanced Features
65
84
66
-
Please find here a [tutorial](https://github.com/angular-architects/module-federation-plugin/blob/main/packages/mf/tutorial/tutorial.md) that shows step by step how to introduce Module Federation into the above mentioned example.
85
+
While the above-mentioned tutorial and blog articles guide you through using Module Federation, this section draws your attention to some advanced aspects of this plugin and Module Federation in general.
67
86
68
-

Since version 1.2, we provide helper functions making dynamic module federation really easy. Just use our ``loadRemoteModule`` function instead of a dynamic ``include``, e. g. together with lazy routes:
90
+
91
+
```typescript
92
+
import { loadRemoteModule } from '@angular-architects/module-federation';
If somehow possible, load the ``remoteEntry`` upfront. This allows Module Federation to take the remote's metadata in consideration when negotiating the versions of the shared libraries.
112
+
113
+
For this, you could call ``loadRemoteEntry`` BEFORE bootstrapping Angular:
The ``bootstrap.ts`` file contains the source code normally found in ``main.ts`` and hence, it calls ``platform.bootstrapModule(AppModule)``. You really need this combination of an upfront file calling loadRemoteEntry and a dynamic import loading another file bootstrapping Angular because Angular itself is already a shared library respected during the version negotiation.
128
+
129
+
Then, when loading the remote Module, just skip the ``remoteEntry`` property:
Beginning with version 1.2, the boilerplate for using ``SharedMappings`` is generated for you. You only need to add your lib's name here.
180
+
181
+
This generated code includes providing the metadata for these libraries for the ``ModuleFederationPlugin`` and adding a plugin making sure that even source code generated by the Angular Compiler uses the shared version of the library.
182
+
183
+
```javascript
184
+
plugins: [
185
+
newModuleFederationPlugin({
186
+
[...]
187
+
shared: {
188
+
[...]
189
+
...sharedMappings.getDescriptors()
190
+
}
191
+
}),
192
+
sharedMappings.getPlugin(),
193
+
],
194
+
```
195
+
196
+
### Pitfalls when sharing libraries of a Monorepo
197
+
198
+
#### Bug with styleUrls
199
+
200
+
Currently, there is, unfortunately, a bug in the experimental CLI/webpack5 integration causing issues when using shared libraries together with components pointing to ``styleUrls``. For the time being, you can work around this issue by removing all ``styleUrls`` in your applications and libraries.
201
+
202
+
#### Sharing a library that is not even used
203
+
204
+
If you shared a local library that is not even used, you get the following error:
Error: C:\Users\Manfred\Documents\projekte\mf-plugin\example\projects\shared-lib\src\public-api.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
209
+
at AngularCompilerPlugin.getCompiledFile (C:\Users\Manfred\Documents\projekte\mf-plugin\example\node_modules\@ngtools\webpack\src\angular_compiler_plugin.js:957:23)
210
+
at C:\Users\Manfred\Documents\projekte\mf-plugin\example\node_modules\@ngtools\webpack\src\loader.js:43:31
211
+
```
212
+
213
+
#### Not exported Components
71
214
215
+
If you use a shared component without exporting it via your library's barrel (``index.ts`` or ``public-api.ts``), you get the following error at runtime:
72
216
73
-
## More Details on Module Federation 📰
217
+
```
218
+
core.js:4610 ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'ɵcmp' of undefined
219
+
TypeError: Cannot read property 'ɵcmp' of undefined
220
+
at getComponentDef (core.js:1821)
221
+
```
74
222
75
-
Have a look at this [article series about Module Federation](https://www.angulararchitects.io/aktuelles/the-microfrontend-revolution-part-2-module-federation-with-angular/).
76
223
77
224
## Angular Trainings, Workshops, and Consulting 👨🏫
0 commit comments