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
Beginning with Angular 13, we had to add some changes to adjust to the Angular CLI. Please see the next section for this.
42
44
45
+
## Update
46
+
47
+
This library supports ``ng update``:
48
+
49
+
```
50
+
ng update @angular-architects/module-federation
51
+
```
52
+
53
+
If you update by hand (e. g. via ``npm install``), make sure you also install a respective version of ngx-build-plus (version 14 for Angular 14, version 13 for Angular 13, etc.)
54
+
43
55
## Upgrade from Angular 12 or lower
44
56
45
57
Beginning with Angular 13, the CLI generates EcmaScript modules instead of script files. This affects how we work with Module Federation a bit.
@@ -50,28 +62,6 @@ Please find information on migrating here:
50
62
51
63
If you start from the scratch, ``ng add`` will take care of these settings.
52
64
53
-
## Upgrade from Version 1.x
54
-
55
-
After updating the libs, you need to adjust the ``webpack.conf.js`` a bit:
56
-
57
-
58
-
```diff
59
-
module.exports = {
60
-
output: {
61
-
uniqueName: "delme3",
62
-
+ publicPath: "auto"
63
-
},
64
-
optimization: {
65
-
runtimeChunk: false
66
-
},
67
-
+ resolve: {
68
-
+ alias: {
69
-
+ ...sharedMappings.getAliases(),
70
-
+ }
71
-
+ },
72
-
[...]
73
-
}
74
-
```
75
65
76
66
## Usage 🛠️
77
67
@@ -81,13 +71,23 @@ module.exports = {
81
71
2. Adjust the generated ``webpack.config.js`` file
82
72
3. Repeat this for further projects in your workspace (if needed)
2.``ng g @angular-architects/module-federation:init``
88
78
3. Adjust the generated ``webpack.config.js`` file
89
79
4. Repeat this for further projects in your workspace (if needed)
90
80
81
+
### 🆕🔥 Version 14+: Use the --type switch to get the new streamlined configuration
82
+
83
+
With version 14, we've introduced a --type switch for ``ng add`` and the ``init`` schematic. Set it to one of the following values to get a more streamlined configuration file:
84
+
85
+
-``host``
86
+
-``dynamic-host``
87
+
-``remote``
88
+
89
+
A dynamic host reads the micro frontend's URLs from a configuration file at runtime.
90
+
91
91
## Getting Started 🧪
92
92
93
93
Please find here a [tutorial](https://github.com/angular-architects/module-federation-plugin/blob/12.0.0/libs/mf/tutorial/tutorial.md) that shows how to use this plugin.
@@ -105,11 +105,8 @@ Please have a look at this [article series about Module Federation](https://www.
105
105
This [example](https://github.com/manfredsteyer/module-federation-plugin-example)
106
106
loads a microfrontend into a shell:
107
107
108
-

109
-
110
108
Please have a look into the example's **readme**. It points you to the important aspects of using Module Federation.
111
109
112
-
113
110
## Advanced Features
114
111
115
112
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.
@@ -190,7 +187,30 @@ Let's assume, you have an Angular CLI Monorepo or an Nx Monorepo using path mapp
190
187
191
188
You can now share such a library across all your micro frontends (apps) in your mono repo. This means, this library will be only loaded once.
192
189
193
-
To accomplish this, just register this lib name with the ``SharedMappings`` instance in your webpack config:
190
+
#### New streamlined configuration in version 14+
191
+
192
+
Beginning with version 14, we use a more steamlined configuration, when using the above mentioned --type switch with one of the following options: ``remote``, ``host``, ``dynamic-host``.
193
+
194
+
This new configuration automatically shares all local libararies. Hence, you don't need to do a thing.
195
+
196
+
However, if you want to control, which local libraries to share, you can use the the ``sharedMappings`` array:
Beginning with version 1.2, the boilerplate for using ``SharedMappings`` is generated for you. You only need to add your lib's name here.
209
229
210
-
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.
230
+
This generated code includes providing 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.
211
231
212
232
```javascript
213
233
plugins: [
@@ -297,6 +317,28 @@ The options passed to shareAll are applied to all dependencies found in your ``p
>Bigthanksto [MichaelEgger-Zickes](https://twitter.com/MikeZks), who came up with these solutions.
323
+
324
+
ModuleFederationallowstodirectlybundleshareddependenciesintoyourapp's bundles. Hence, you don'tneedtoloadanadditionalbundlepershareddependency. Thiscanbeinterestingtoimproveanapplication's startup performance, when there are lots of shared dependencies.
325
+
326
+
Onepossibleusageforimprovingthestartuptimesistoset``eager``to``true``**just**forthehost. Theremotesloadedlatercanreusetheseeagerdependenciesalothoughthey've been shipped via the host'sbundle (e. g. its``main.js``). Thisworksbest, ifthehostalwayshasthehighestcompatibleversionsoftheshareddependencies. Also, inthiscase, youdon't need to load the remote entry points upfront.
327
+
328
+
Whilethe``eager``flagisanoutoftheboxfeatureprovidedbymodulefederationsinceitsveryfirstdays, weneedtoadjustthewebpackconfigurationusedbytheAngularCLIabittoavoidcodeduplicationinthegeneratedbundles. Thenew``withModuleFederationPlugin``helperthathasbeenintroduceswiththisplugin's version 14 and is the basis for the new streamlined configuration, does this by default. The config just needs to set eager to ``true``.
Asshowninthelastexample, wealsoaddedanotherproperty: pinned. Thismakessure, theshareddependencyinputintotheapplication's (e. g. the host's) bundle, even though it's not used there. This allows to preload dependencies that are needed later but subsequently loaded micro frontends via one bundle.
341
+
300
342
### Nx Integration
301
343
302
344
If the plugin detects that you are using Nx (it basically looks for a ``nx.json``), it uses the builders provided by Nx.
@@ -425,8 +467,6 @@ shared: share({
425
467
})
426
468
```
427
469
428
-
429
-
430
470
#### NotexportedComponents
431
471
432
472
Ifyouuseasharedcomponentwithoutexportingitviayourlibrary's barrel (``index.ts`` or ``public-api.ts``), you get the following error at runtime:
0 commit comments