Skip to content

Commit 8baf352

Browse files
committed
feat: rc for v14
1 parent edcd1e1 commit 8baf352

File tree

12 files changed

+145
-138
lines changed

12 files changed

+145
-138
lines changed

angular.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@
9090
"glob": "collection.json",
9191
"output": "."
9292
},
93+
{
94+
"input": ".",
95+
"glob": "migrations.json",
96+
"output": "."
97+
},
9398
{
9499
"input": "./libs/mf",
95100
"glob": "builders.json",

libs/mf-runtime/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@angular-architects/module-federation-runtime",
33
"license": "MIT",
4-
"version": "14.0.0-beta.1",
4+
"version": "14.0.0-beta.1.12",
55
"peerDependencies": {
66
"@angular/common": ">=12.0.0",
77
"@angular/core": ">=12.0.0"

libs/mf-tools/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"name": "@angular-architects/module-federation-tools",
3-
"version": "14.0.0-beta.1",
3+
"version": "14.0.0-rc.1",
44
"license": "MIT",
55
"peerDependencies": {
66
"@angular/common": ">=11.0.0",
77
"@angular/core": ">=11.0.0",
88
"@angular/router": ">=11.0.0",
9-
"@angular-architects/module-federation": "^14.0.0-beta.0",
9+
"@angular-architects/module-federation": "^14.0.0-rc.1",
1010
"@angular/platform-browser": ">=11.0.0",
1111
"rxjs": ">= 6.0.0"
1212
},

libs/mf/README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ Since Version 1.2, we also provide some advanced features like:
3939

4040
✅ Issues with sharing libs in monorepos are resolved (always worked with multiple repos)
4141

42+
## Upgrade from Angular 12
43+
44+
Beginning with Angular 13, the CLI generates EcmaScript modules instead of script files. This affects how we work with Module Federation a bit.
45+
46+
Please find information on migrating here:
47+
48+
[Migration Guide for Angular 13+](https://github.com/angular-architects/module-federation-plugin/blob/main/migration-guide.md)
49+
50+
If you start from the scratch, ``ng add`` will take care of these settings.
51+
4252
## Upgrade from Version 1.x
4353

4454
After updating the libs, you need to adjust the ``webpack.conf.js`` a bit:
@@ -64,10 +74,19 @@ module.exports = {
6474

6575
## Usage 🛠️
6676

67-
1. ``ng add @angular-architects/module-federation@next``
77+
### Angular CLI
78+
79+
1. ``ng add @angular-architects/module-federation``
6880
2. Adjust the generated ``webpack.config.js`` file
6981
3. Repeat this for further projects in your workspace (if needed)
7082

83+
## Nx
84+
85+
1. ``npm install @angular-architects/module-federation``
86+
2. ``ng g @angular-architects/module-federation:init``
87+
3. Adjust the generated ``webpack.config.js`` file
88+
4. Repeat this for further projects in your workspace (if needed)
89+
7190
## Getting Started 🧪
7291

7392
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.

libs/mf/package.json

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@angular-architects/module-federation",
3-
"version": "14.0.0-beta.1",
3+
"version": "14.0.0-rc.1",
44
"license": "MIT",
55
"repository": {
66
"type": "GitHub",
@@ -17,10 +17,20 @@
1717
"schematics": "./collection.json",
1818
"builders": "./builders.json",
1919
"dependencies": {
20-
"@angular-architects/module-federation-runtime": "14.0.0-beta.1",
20+
"@angular-architects/module-federation-runtime": "14.0.0-rc.1",
2121
"word-wrap": "^1.2.3",
2222
"callsite": "^1.0.0",
2323
"node-fetch": "^2.6.1",
24-
"semver": "^7.3.5"
24+
"semver": "^7.3.5",
25+
"ngx-build-plus":"^13.0.0"
26+
},
27+
"peerDependencies": {
28+
},
29+
"ng-update": {
30+
"migrations": "./migrations.json",
31+
"package-group": [
32+
"@angular-architects/module-federation-tools",
33+
"ngx-build-plus"
34+
]
2535
}
2636
}

libs/mf/src/schematics/mf/schematic.ts

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66

77
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
88
import { strings } from '@angular-devkit/core';
9-
9+
import * as json5 from 'json5';
1010
import * as semver from 'semver'
1111

1212
// import { spawn } from 'cross-spawn';
@@ -17,6 +17,7 @@ import { prodConfig } from './prod-config';
1717
import { MfSchematicSchema } from './schema';
1818

1919
import { addPackageJsonDependency, NodeDependencyType } from '@schematics/angular/utility/dependencies';
20+
import { hostname } from 'os';
2021

2122
// export async function npmInstall(packageName: string) {
2223
// await new Promise<boolean>((resolve) => {
@@ -248,6 +249,7 @@ export default function config (options: MfSchematicSchema): Rule {
248249

249250
projectConfig.architect.serve.builder = serveBuilder;
250251
projectConfig.architect.serve.options.port = port;
252+
projectConfig.architect.serve.options.publicHost = `http://localhost:${port}`;
251253

252254
// Only needed for ngx-build-plus
253255
if (!options.nxBuilders) {
@@ -269,20 +271,25 @@ export default function config (options: MfSchematicSchema): Rule {
269271
projectConfig.architect['extract-i18n'].options.extraWebpackConfig = configPath;
270272
}
271273

274+
275+
updateTsConfig(tree, tsConfigName);
276+
277+
278+
272279
const ssrMappings = generateSsrMappings(workspace, projectName);
273280

274281
tree.overwrite(workspaceFileName, JSON.stringify(workspace, null, '\t'));
275282

276283
updatePackageJson(tree);
277284

278-
addPackageJsonDependency(tree, {
279-
name: 'ngx-build-plus',
280-
type: NodeDependencyType.Dev,
281-
version: '^13.0.1',
282-
overwrite: true
283-
});
285+
// addPackageJsonDependency(tree, {
286+
// name: 'ngx-build-plus',
287+
// type: NodeDependencyType.Dev,
288+
// version: '^13.0.1',
289+
// overwrite: true
290+
// });
284291

285-
context.addTask(new NodePackageInstallTask());
292+
// context.addTask(new NodePackageInstallTask());
286293

287294
return chain([
288295
makeMainAsync(main),
@@ -293,6 +300,23 @@ export default function config (options: MfSchematicSchema): Rule {
293300
}
294301
}
295302

303+
function updateTsConfig(tree, tsConfigName: string) {
304+
const tsConfig = json5.parse(tree.read(tsConfigName).toString('utf-8'));
305+
const target = tsConfig.compilerOptions.target as string;
306+
let targetVersion = 0;
307+
308+
if (target
309+
&& target.toLocaleLowerCase().startsWith("es")
310+
&& target.length > 2) {
311+
targetVersion = parseInt(target.substring(2));
312+
}
313+
314+
if (targetVersion < 2020) {
315+
tsConfig.compilerOptions.target = 'es2020';
316+
}
317+
318+
tree.overwrite(tsConfigName, JSON.stringify(tsConfig, null, 2));
319+
}
296320

297321
function generateRemoteConfig(workspace: any, projectName: string) {
298322
let remotes = '';
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export interface BootAsyncSchema {
2+
project: string;
3+
async: boolean;
4+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"$schema": "http://json-schema.org/schema",
3+
"$id": "mf",
4+
"title": "",
5+
"type": "object",
6+
"properties": {
7+
}
8+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Rule } from '@angular-devkit/schematics';
2+
3+
export function index(): Rule {
4+
5+
return async function (tree, context) {
6+
7+
console.info(`!!!
8+
Angular 13 compiles bundles as EcmaScript modules.
9+
Hence, we need to adjust how we use Module Federation.
10+
We've got you covered. Please find all information here:
11+
https://github.com/angular-architects/module-federation-plugin/blob/main/migration-guide.md
12+
!!!
13+
`);
14+
}
15+
}

migration-guide.md

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Migration Guide for Angular 13
22

3-
Beginning with version 13, the Angular CLI compiles bundles as EcmaScript modules. This also effects how entry points for Module Federation are generated. This guide shows how you can adjust to this.
3+
Beginning with version 13, the Angular CLI compiles emits EcmaScript modules. This also effects how entry points for Module Federation are generated. This guide shows how you can adjust to this.
44

55
## Big Thanks
66

@@ -10,41 +10,35 @@ Big thanks to all the people, that helped with this migration:
1010
- [Colum Ferry](https://twitter.com/ferrycolum), Senior Software Engineer
1111
at NRWL
1212
- [Thomas Sandeep](https://github.com/SandeepThomas)
13+
- [Michael Zikes](https://twitter.com/MikeZks)
1314

15+
## Upgrade to the Newest Version of @angular-architects/module-federation
1416

15-
## Force the CLI into the Newest Version of Webpack
17+
```
18+
yarn add @angular-architects/[email protected]
19+
```
1620

17-
As long as the CLI doesn't support webpack 5.64.4 or higher, we need to force it into this version. It seems like that this is necessary for CLI 13.0.x, while 13.1.x and above will ship with a fitting webpack version. In the latter case, you can skip this section. Otherwise, add this section to your ``package.json``:
21+
## Upgrade to Angular and Angular CLI 13.1 (!) or higher
1822

19-
```diff
20-
+ "resolutions": {
21-
+ "webpack": "5.64.4"
22-
+ },
23-
```
23+
As we need a newer webpack version, don't go with Angular 13.0 but with 13.1 or higher.
2424

25-
Then, nuke your ``node_modules`` folder and install the dependencies with ``yarn`` (!). Please note, that yarn is needed for respecting the ``resolutions`` section. Once, the CLI ships with a fitting webpack version you can git rid of this section and use other package manager.
25+
## Update your Compilation Target
2626

27-
If you haven't created your project with yarn, also add the following section to your ``angular.json``:
27+
In your ``tsconfig.json`` or ``tsconfig.base.json``, make sure, your compilation ``target`` is ``es2020`` or higher:
2828

29-
```diff
29+
30+
```json
3031
{
31-
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
32-
"version": 1,
33-
+ "cli": {
34-
+ "packageManager": "yarn"
35-
+ },
32+
"compileOnSave": false,
33+
"compilerOptions": {
34+
[...]
35+
"target": "es2020",
36+
[...]
37+
},
3638
[...]
3739
}
3840
```
3941

40-
This makes sure that calls to commands like ``ng add`` use yarn too.
41-
42-
## Upgrade to the Newest Version of @angular-architects/module-federation
43-
44-
```
45-
yarn add @angular-architects/[email protected]
46-
```
47-
4842
## Adjust your webpack Configs
4943

5044
Add the following setting to all your webpack configs:
@@ -134,9 +128,25 @@ To prevent issues with live reloads, you need to add a ``publicHost`` property t
134128
[...]
135129
```
136130

137-
### Advanced: Loading Script-based Remotes
131+
### Advanced: Dynamic Federation with Script-based Remotes
132+
133+
If you also want to load (existing) script-based remotes into your shell, e. g. remotes built with Angular 12 used for a [Multi-Version/Multi-Framework setup](https://www.npmjs.com/package/@angular-architects/module-federation-tools), you can pass ``type: 'script'`` to both, ``loadRemoteModule`` and ``loadRemoteEntry``. In this case, you also need to pass a ``remoteName``.
138134

139-
If you also want to load script-based remotes into your shell, e. g. remotes build with Angular 12 used for a [Multi-Version/Multi-Framework setup](https://www.npmjs.com/package/@angular-architects/module-federation-tools), you can pass ``type: 'script'`` to both, ``loadRemoteModule`` and ``loadRemoteEntry``. In this case, you also need to pass a ``remoteName``.
135+
### Advanced: Static Federation with Script-based Remotes
136+
137+
If you want to load (existing) script-based remote into your shell, e. g. such built with Angular 12, you can use the following syntax in the shell's ``webpack.config.js``.
138+
139+
In the following example, ``mfe1`` is loaded as a module while ``mfe2`` is loaded as a script:
140+
141+
```javascript
142+
remotes: {
143+
// Load as module:
144+
mfe1": "mfe2@http://localhost:3000/remoteEntry.js",
145+
146+
// Load as script:
147+
mfe2": "script mfe2@http://localhost:3000/remoteEntry.js",
148+
}
149+
```
140150

141151
### Advanced: Opting-out of Using EcmaScript Modules
142152

0 commit comments

Comments
 (0)