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: libs/native-federation/README.md
+51-12Lines changed: 51 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,10 +5,15 @@ Native Federation is a "browser-native" implementation of the successful mental
5
5
## Features 🔥
6
6
7
7
- ✅ Mental Model of Module Federation
8
-
- ✅ Future Proof: Independent of build tools like webpack
9
-
- ✅ Embraces Import Maps - an emerging web standard
8
+
- ✅ Future Proof: Uses **Web Standards** to be **independent** of build tools like webpack
9
+
- ✅ Neat Angular-Integration: **Directly delegates** to Angular's new ultra-fast esbuild-based ApplicationBuilder to **prevent diverging** from the Angular standard.
10
+
11
+
### More
12
+
13
+
- ✅ Embraces ESM and Import Maps - an emerging web standard
10
14
- ✅ Easy to configure: We use the same API and Schematics as for our Module Federation plugin
11
15
- ✅ Blazing Fast: The reference implementation not only uses the fast esbuild; it also caches already built shared dependencies.
16
+
- ✅ Supports Angular SSR and Incremental Hydration (since 18@latest)
12
17
13
18
## Prerequisite
14
19
@@ -23,15 +28,20 @@ We will at least provide a new version of this package per Angular major. If nec
23
28
- Use version 16.1.x for Angular 16.1.x
24
29
- Use version 16.2.x for Angular 16.2.x
25
30
- Use version 17.x for Angular 17.x
26
-
- Use version 17.1.x for Angular 17.1+
27
-
- Use version 18.x for Angular 18+
28
-
- Use version 18.1.x for Angular 18.1+
29
-
- Use version 18.2.x for Angular 18.2+
31
+
- Use version 17.1.x for Angular 17.1
32
+
- Use version 18.x for Angular 18.0.x
33
+
- Use version 18.1.x for Angular 18.1.x
34
+
- Use version 18.2.x for Angular 18.2.x
35
+
- Use version 19.x for Angular 19.x
30
36
31
37
## Migration from Module Federation
32
38
33
39
If you currently use Angular with Module Federation, you can follow our [Migration Guide](https://github.com/angular-architects/module-federation-plugin/blob/main/libs/native-federation/docs/migrate.md) to migrate to Native Federation and Angular's new fast esbuild-based build system.
34
40
41
+
## Using Module Federation and Native Federation Side-by-Side
42
+
43
+
[In this article](https://www.angulararchitects.io/en/blog/combining-native-federation-and-module-federation/) we describe, how to use both technologies side-by-side.
44
+
35
45
## Updates
36
46
37
47
You can use `ng update` for updating Native Federation.
@@ -40,7 +50,7 @@ Notes for [updating to version 18](https://github.com/angular-architects/module-
40
50
41
51
## Angular Integration
42
52
43
-
Since 17.1, Native Federation for Angular uses the Angular CLI's `esbuild`-based **Application Builder** and the CLI's **Dev Server** to keep track with all the innovations and performance-improvements in that space.
53
+
Since 17.1, Native Federation for Angular uses the Angular CLI's `esbuild`-based **Application Builder** and the CLI's **Dev Server** to **keep track with all the innovations and performance-improvements provided by the Angular CLI team.**
44
54
45
55
Please find some [information for upgrading to 17.1. here](https://github.com/angular-architects/module-federation-plugin/blob/main/libs/native-federation/migrate-appbuilder.md).
46
56
@@ -318,11 +328,7 @@ Now, by clicking at the 2nd menu item, you can load the remote directly into the
318
328
319
329
### When to use this package?
320
330
321
-
If you like the idea of webpack Module Federation but want to switch over to Angular's new esbuild builder (currently in developer preview), you can use this package.
322
-
323
-
### Error: File 'src\main.ts' is missing from the TypeScript compilation. [plugin angular-compiler]
324
-
325
-
It seems like the current version of Angular's esbuild builder has an issue with paths on Windows when using the traditional command prompt. For the time being, try to ng serve and ng build your application via PowerShell, the git bash, or WSL.
331
+
If you like the idea of webpack Module Federation but want to switch over to Angular's new esbuild builder, you can use this package.
326
332
327
333
### I get an error when preparing shared packages. What to do?
328
334
@@ -338,6 +344,39 @@ For this, there are several reasons:
338
344
339
345
- Perhaps your shared packages contain some code esbuild cannot transfer to EcmaScript modules. This should not be the case for packages, built with the Angular CLI or Nx and the underlying package ng-packagr. If this happens, please let us know about the package causing troubles.
340
346
347
+
### How to deal with CommonJS Packages?
348
+
349
+
The good message is, that the official Angular Package Format defines the usage of ECMA Script Modules (ESM) for years. This is the future-proof standard, Native Federation is built upon and all npm packages created with the Angular CLI follow. If you use older CommonJS-based packages, Native Federation automatically converts them to ESM. Depending on the package, this might change some details. Here, you find some [information for dealing with CommonJS packages](https://shorturl.at/jmzH0).
350
+
351
+
## How to Deal with Transitive Dependencies?
352
+
353
+
Since version 18@latest, also transitive dependencies are shared. For instance, `primeng` uses a lib `@primeuix/styled` for theming. The latter one is now shared too if `primeng` is. This prevents possible challanges but also results in more bundles. If you don't want to share such a transitive dependency, just put it into the `skip` list.
354
+
355
+
## How to Manually Define a Package's Entry Point?
356
+
357
+
Usually, Native Federation automatically detects entry points into shared packages. If the packages neither align with the official standard nor with typical conventions beyond these standards, you can also directly provide the entry point:
358
+
359
+
```js
360
+
module.exports=withNativeFederation({
361
+
shared: {
362
+
...shareAll({
363
+
singleton:true,
364
+
strictVersion:true,
365
+
requiredVersion:'auto',
366
+
}),
367
+
'test-pkg': {
368
+
packageInfo: {
369
+
entryPoint:'/path/to/test-pkg/entry.mjs',
370
+
version:'1.0.0',
371
+
esm:true,
372
+
},
373
+
},
374
+
},
375
+
});
376
+
```
377
+
378
+
As in such cases, we cannot expect to find a `package.json` nearby, you also have to specifiy the `version` and the `esm` flag by hand.
379
+
341
380
### How to speed up package preparation during the build process
342
381
343
382
The already prepared packages are cached in `node_modules/.cache`. Make sure, this folder is reused across subsequent build process runs.
Copy file name to clipboardExpand all lines: libs/native-federation/docs/share-faq.md
+41Lines changed: 41 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -55,3 +55,44 @@ skip: [
55
55
/^my-package/, // RegExp
56
56
];
57
57
```
58
+
59
+
As an alternative, you can also provide a lambda expression:
60
+
61
+
```typescript
62
+
skip: [
63
+
'this-package', // string-based entry
64
+
'that-package', // another string-based one
65
+
(p) =>p.startsWith('my-package'), // RegExp
66
+
];
67
+
```
68
+
69
+
Please note, that a provided string is fully compared (not with startsWith semantic). Hence, in this example shown, `this-package` is excluded but not secondary entry points like `this-package/interop`.
70
+
71
+
## Transitive Dependencies
72
+
73
+
Since version 18@latest, also transitive dependencies are shared. For instance, `primeng` and individual theming packages for `primeng` communicate via the lib `@primeuix/styled`. The latter one is now shared too together with the two former ones. This prevents possible challanges but also results in more bundles. If you don't want to share such a transitive dependency, just put it into the `skip` list.
74
+
75
+
## Manually Providing a Package's Entry Point
76
+
77
+
Usually, Native Federation automatically detects entry points into shared packages. If the packages neither align with the official standard nor with typical conventions beyond these standards, you can also directly provide the entry point:
78
+
79
+
```js
80
+
module.exports=withNativeFederation({
81
+
shared: {
82
+
...shareAll({
83
+
singleton:true,
84
+
strictVersion:true,
85
+
requiredVersion:'auto',
86
+
}),
87
+
'test-pkg': {
88
+
packageInfo: {
89
+
entryPoint:'/path/to/test-pkg/entry.mjs',
90
+
version:'1.0.0',
91
+
esm:true,
92
+
},
93
+
},
94
+
},
95
+
});
96
+
```
97
+
98
+
As in such cases, we cannot expect to find a `package.json` nearby, you also have to specifiy the `version` and the `esm` flag by hand.
0 commit comments