@yaagoub/federation-tools 1.2.7 β 1.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +190 -33
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,63 +1,220 @@
|
|
|
1
1
|
# FederationTools
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**FederationTools** is a lightweight utility library designed to simplify **environment variables**, **assets**, and **internationalization (i18n)** management across **Angular micro-frontend architectures** (Module Federation / Native Federation).
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
It provides a **single, consistent API** that works across the **shell** and all **remote MFEs**, without iframes and without leaking configuration to `window`.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## π¦ Installation
|
|
10
|
+
|
|
11
|
+
Add the library to your workspace:
|
|
8
12
|
|
|
9
13
|
```bash
|
|
10
|
-
|
|
14
|
+
npm install @yaagoub/federation-tools
|
|
11
15
|
```
|
|
12
16
|
|
|
13
|
-
|
|
17
|
+
---
|
|
14
18
|
|
|
15
|
-
|
|
16
|
-
|
|
19
|
+
## π Project Structure (Shell)
|
|
20
|
+
|
|
21
|
+
The shell application acts as the **single source of truth** for:
|
|
22
|
+
|
|
23
|
+
* environment variables
|
|
24
|
+
* translations
|
|
25
|
+
* asset origins
|
|
26
|
+
|
|
27
|
+
Recommended structure:
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
βββ πsettings
|
|
31
|
+
βββ πenv
|
|
32
|
+
β βββ env.json # Shell environment variables
|
|
33
|
+
β
|
|
34
|
+
βββ πi18n
|
|
35
|
+
β βββ en.json # English translations
|
|
36
|
+
β βββ ar.json # Arabic translations
|
|
37
|
+
β
|
|
38
|
+
βββ πmanifest
|
|
39
|
+
βββ πassets
|
|
40
|
+
β βββ assets.manifest.json
|
|
41
|
+
β {
|
|
42
|
+
β "shell": "http://localhost:4200",
|
|
43
|
+
β "mfe1": "http://localhost:4201",
|
|
44
|
+
β "mfe2": "http://localhost:4202"
|
|
45
|
+
β }
|
|
46
|
+
β
|
|
47
|
+
βββ πenv
|
|
48
|
+
β βββ env.manifest.json
|
|
49
|
+
β {
|
|
50
|
+
β "shell": "http://localhost:4200",
|
|
51
|
+
β "mfe1": "http://localhost:4201",
|
|
52
|
+
β "mfe2": "http://localhost:4202"
|
|
53
|
+
β }
|
|
54
|
+
β
|
|
55
|
+
βββ πi18n
|
|
56
|
+
βββ i18n.manifest.json
|
|
57
|
+
{
|
|
58
|
+
"shell": "http://localhost:4200",
|
|
59
|
+
"mfe1": "http://localhost:4201",
|
|
60
|
+
"mfe2": "http://localhost:4202"
|
|
61
|
+
}
|
|
17
62
|
```
|
|
18
63
|
|
|
19
|
-
|
|
64
|
+
for remotes Recommended structure:
|
|
20
65
|
|
|
21
|
-
|
|
66
|
+
```
|
|
67
|
+
βββ πsettings
|
|
68
|
+
βββ πenv
|
|
69
|
+
β βββ env.json # mfe environment variables
|
|
70
|
+
β
|
|
71
|
+
βββ πi18n
|
|
72
|
+
β βββ en.json # English translations
|
|
73
|
+
β βββ ar.json # Arabic translations
|
|
74
|
+
```
|
|
22
75
|
|
|
23
|
-
|
|
24
|
-
|
|
76
|
+
Each manifest defines **where to fetch data from** for each micro frontend.
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## βοΈ Development Configuration (Angular)
|
|
81
|
+
|
|
82
|
+
During development, expose the manifests and settings using the Angular assets configuration:
|
|
83
|
+
|
|
84
|
+
```json
|
|
85
|
+
"development": {
|
|
86
|
+
"assets": [
|
|
87
|
+
{
|
|
88
|
+
"glob": "**/*",
|
|
89
|
+
"input": "projects/lkhedma/public"
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
"glob": "env.manifest.json",
|
|
93
|
+
"input": "projects/../src/settings/manifest/env",
|
|
94
|
+
"output": "."
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"glob": "assets.manifest.json",
|
|
98
|
+
"input": "projects/../src/settings/manifest/assets",
|
|
99
|
+
"output": "."
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
"glob": "i18n.manifest.json",
|
|
103
|
+
"input": "projects/../src/settings/manifest/i18n",
|
|
104
|
+
"output": "."
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
"glob": "**/*",
|
|
108
|
+
"input": "projects/../src/settings/i18n",
|
|
109
|
+
"output": "i18n"
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
"glob": "env.json",
|
|
113
|
+
"input": "projects/../src/settings/env",
|
|
114
|
+
"output": "."
|
|
115
|
+
}
|
|
116
|
+
],
|
|
117
|
+
"optimization": false,
|
|
118
|
+
"extractLicenses": false,
|
|
119
|
+
"sourceMap": true
|
|
120
|
+
}
|
|
25
121
|
```
|
|
26
122
|
|
|
27
|
-
|
|
123
|
+
> π‘ In production, these files are typically served by the shell (CDN, Nginx, or gateway).
|
|
28
124
|
|
|
29
|
-
|
|
125
|
+
---
|
|
30
126
|
|
|
31
|
-
|
|
127
|
+
## π Shell Providers Setup
|
|
32
128
|
|
|
33
|
-
|
|
34
|
-
```bash
|
|
35
|
-
cd dist/federation-tools
|
|
36
|
-
```
|
|
129
|
+
Register the FederationTools providers **once** in the shell application:
|
|
37
130
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
131
|
+
```ts
|
|
132
|
+
provideFederationAsset(),
|
|
133
|
+
provideFederationEnv(),
|
|
134
|
+
provideFederationTranslation('en') // default language
|
|
135
|
+
```
|
|
42
136
|
|
|
43
|
-
|
|
137
|
+
These providers automatically:
|
|
44
138
|
|
|
45
|
-
|
|
139
|
+
* load manifests
|
|
140
|
+
* fetch remote data
|
|
141
|
+
* cache results
|
|
142
|
+
* expose a unified API to all MFEs
|
|
46
143
|
|
|
47
|
-
|
|
48
|
-
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## πΌοΈ Federated Assets
|
|
147
|
+
|
|
148
|
+
Use assets from **any MFE** by prefixing the asset name with the micro frontend key.
|
|
149
|
+
|
|
150
|
+
```html
|
|
151
|
+
<img [asset]="'mfe1:logo.png'" />
|
|
49
152
|
```
|
|
50
153
|
|
|
51
|
-
|
|
154
|
+
### Supported elements
|
|
52
155
|
|
|
53
|
-
|
|
156
|
+
The `asset` directive works with:
|
|
54
157
|
|
|
55
|
-
|
|
56
|
-
|
|
158
|
+
* `img`
|
|
159
|
+
* `video`
|
|
160
|
+
* `audio`
|
|
161
|
+
* `iframe`
|
|
162
|
+
* `source`
|
|
163
|
+
* `a`
|
|
164
|
+
* `object`
|
|
165
|
+
|
|
166
|
+
The prefix (`mfe1`) must exist in `assets.manifest.json`.
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
## π Internationalization (i18n)
|
|
171
|
+
|
|
172
|
+
FederationTools provides a federated translation system shared across all MFEs.
|
|
173
|
+
|
|
174
|
+
### Template usage
|
|
175
|
+
|
|
176
|
+
```html
|
|
177
|
+
{{ 'home.title' | t }}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### Programmatic usage
|
|
181
|
+
|
|
182
|
+
```ts
|
|
183
|
+
import { inject } from '@angular/core';
|
|
184
|
+
import { TranslationService } from '@yaagoub/federation-tools';
|
|
185
|
+
|
|
186
|
+
const translationService = inject(TranslationService);
|
|
187
|
+
|
|
188
|
+
translationService.t('home.title');
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Translations are:
|
|
192
|
+
|
|
193
|
+
* loaded lazily
|
|
194
|
+
* merged across shell + MFEs
|
|
195
|
+
* automatically updated when the language changes
|
|
196
|
+
|
|
197
|
+
---
|
|
198
|
+
|
|
199
|
+
## π Environment Variables
|
|
200
|
+
|
|
201
|
+
Environment variables are **not exposed on `window`** and are only accessible through the FederationTools API.
|
|
202
|
+
|
|
203
|
+
### Waiting for environment initialization
|
|
204
|
+
|
|
205
|
+
```ts
|
|
206
|
+
import { from } from 'rxjs';
|
|
207
|
+
import { waitForFederationEnv } from '@yaagoub/federation-tools';
|
|
208
|
+
|
|
209
|
+
from(waitForFederationEnv('mfe1')).subscribe(env => {
|
|
210
|
+
// Safe access to federated environment variables
|
|
211
|
+
});
|
|
57
212
|
```
|
|
58
213
|
|
|
59
|
-
|
|
214
|
+
### Key guarantees
|
|
60
215
|
|
|
61
|
-
|
|
216
|
+
* βοΈ Shell loads the environment first
|
|
217
|
+
* βοΈ MFEs wait safely for availability
|
|
218
|
+
* βοΈ Immutable, frozen configuration
|
|
219
|
+
* βοΈ No global leaks
|
|
62
220
|
|
|
63
|
-
For more information on using the Angular CLI, including detailed command references, visit the [Angular CLI Overview and Command Reference](https://angular.dev/tools/cli) page.
|