Skip to content

Commit b4d3837

Browse files
committed
1 parent bb1e075 commit b4d3837

File tree

6 files changed

+58
-50
lines changed

6 files changed

+58
-50
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"scripts": {
66
"nx": "nx",
77
"start": "nx serve",
8-
"build": "nx build",
8+
"build": "nx build mf --prod",
99
"test": "nx test",
1010
"lint": "nx workspace-lint && nx lint",
1111
"e2e": "nx e2e",

packages/mf/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ The module federation config is a **partial** webpack configuration. It only con
3333
2. Adjust the generated ``webpack.config.js`` file
3434
3. Repeat this for further projects in your workspace (if needed)
3535

36-
## Notes for CLI 11 BETA (next.XY) 🧐
36+
## Opting in into webpack 5 with CLI 11 🧐
3737

3838
- You need to use **yarn** b/c it allows to override dependencies
3939
- Existing Projects: ``ng config -g cli.packageManager yarn``
@@ -43,31 +43,31 @@ The module federation config is a **partial** webpack configuration. It only con
4343

4444
```json
4545
"resolutions": {
46-
"webpack": "5.0.0"
46+
"webpack": "^5.0.0"
4747
},
4848
```
4949

5050
- Run **yarn** to install all packages
5151

52-
Please note that the current CLI **beta** lacks some features when using it with webpack 5, e. g. **reloading an application in debug mode** (when using ng serve). Hence, you have to restart ng serve after a change. This is just a temporal limitation and will be solved with one of the upcoming versions.
52+
Please that the CLI's webpack 5 support is current experimental.
5353

5454
## Example 📽️
5555

5656
This [example](https://github.com/manfredsteyer/module-federation-plugin-example)
5757
loads a microfrontend into a shell:
5858

59-
![Microfrontend Loaded into Shell](./tutorial/result.png)
59+
![Microfrontend Loaded into Shell](https://github.com/angular-architects/module-federation-plugin/raw/main/packages/mf/tutorial/result.png)
6060

6161
Please have a look into the example's **readme**. It points you to the important aspects of using Module Federation.
6262

6363

6464
## Tutorial 🧪
6565

66-
Please find here a [tutorial](./tutorial/tutorial.md) that shows step by step how to introduce Module Federation into the above mentioned example.
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.
6767

68-
![Microfrontend Loaded into Shell](./tutorial/result.png)
68+
![Microfrontend Loaded into Shell](https://github.com/angular-architects/module-federation-plugin/raw/main/packages/mf/tutorial/result.png)
6969

70-
[>> Start Tutorial](./tutorial/tutorial.md)
70+
[>> Start Tutorial](https://github.com/angular-architects/module-federation-plugin/blob/main/packages/mf/tutorial/tutorial.md)
7171

7272

7373
## More Details on Module Federation 📰

packages/mf/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@angular-architects/module-federation",
3-
"version": "1.0.1",
3+
"version": "1.1.0",
44
"license": "MIT",
55
"repository": {
66
"type": "GitHub",

packages/mf/src/create-config.ts

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,38 @@ export function createConfig(projectName: string, root: string, port: number): s
22

33
return `const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");
44
5-
module.exports = {
6-
output: {
7-
publicPath: "http://localhost:${port}/",
8-
uniqueName: "${projectName}"
9-
},
10-
optimization: {
11-
// Only needed to bypass a temporary bug
12-
runtimeChunk: false
13-
},
14-
plugins: [
15-
new ModuleFederationPlugin({
16-
17-
// For remotes (please adjust)
18-
/*
19-
name: "${projectName}",
20-
library: { type: "var", name: "${projectName}" },
21-
filename: "remoteEntry.js",
22-
exposes: {
23-
'./Component': './${root}/src/app/app.component.ts',
24-
},
25-
*/
26-
27-
// For hosts (please adjust)
28-
/*
29-
remotes: {
30-
'mfe1': "mfe1@http://localhost:3000/remoteEntry.js"
31-
},
32-
*/
5+
module.exports = {
6+
output: {
7+
uniqueName: "${projectName}"
8+
},
9+
optimization: {
10+
// Only needed to bypass a temporary bug
11+
runtimeChunk: false
12+
},
13+
plugins: [
14+
new ModuleFederationPlugin({
15+
16+
// For remotes (please adjust)
17+
// name: "${projectName}",
18+
// filename: "remoteEntry.js",
19+
// exposes: {
20+
// './Component': './${root}/src/app/app.component.ts',
21+
// },
22+
23+
// For hosts (please adjust)
24+
// remotes: {
25+
// 'mfe1': "mfe1@http://localhost:3000/remoteEntry.js"
26+
// },
3327
34-
shared: ["@angular/core", "@angular/common", "@angular/router"]
35-
})
36-
],
37-
};
28+
shared: {
29+
"@angular/core": { singleton: true, strictVersion: true },
30+
"@angular/common": { singleton: true, strictVersion: true },
31+
"@angular/router": { singleton: true, strictVersion: true }
32+
}
33+
34+
})
35+
],
36+
};
3837
`;
3938

4039
}

packages/mf/tutorial/tutorial.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This tutorial shows how to use Webpack Module Federation together with the Angular CLI and the ``@angular-architects/module-federation`` plugin. The goal is to make a shell capable of **loading a separately compiled and deployed microfrontend**:
44

5-
![Microfrontend Loaded into Shell](./result.png)
5+
![Microfrontend Loaded into Shell](https://github.com/angular-architects/module-federation-plugin/raw/main/packages/mf/tutorial/result.png)
66

77

88
## Part 1: Clone and Inspect the Starterkit
@@ -68,7 +68,6 @@ Now, let's activate and configure module federation:
6868
6969
module.exports = {
7070
output: {
71-
publicPath: "http://localhost:3000/",
7271
uniqueName: "mfe1"
7372
},
7473
optimization: {
@@ -80,14 +79,16 @@ Now, let's activate and configure module federation:
8079
8180
// For remotes (please adjust)
8281
name: "mfe1",
83-
library: { type: "var", name: "mfe1" },
8482
filename: "remoteEntry.js",
8583
8684
exposes: {
8785
'./Module': './projects/mfe1/src/app/flights/flights.module.ts',
8886
},
89-
90-
shared: ["@angular/core", "@angular/common", "@angular/router"]
87+
shared: {
88+
"@angular/core": { singleton: true, strictVersion: true },
89+
"@angular/common": { singleton: true, strictVersion: true },
90+
"@angular/router": { singleton: true, strictVersion: true }
91+
}
9192
})
9293
],
9394
};
@@ -102,7 +103,6 @@ Now, let's activate and configure module federation:
102103
103104
module.exports = {
104105
output: {
105-
publicPath: "http://localhost:5000/",
106106
uniqueName: "shell"
107107
},
108108
optimization: {
@@ -114,7 +114,11 @@ Now, let's activate and configure module federation:
114114
remotes: {
115115
'mfe1': "mfe1@http://localhost:3000/remoteEntry.js"
116116
},
117-
shared: ["@angular/core", "@angular/common", "@angular/router"]
117+
shared: {
118+
"@angular/core": { singleton: true, strictVersion: true },
119+
"@angular/common": { singleton: true, strictVersion: true },
120+
"@angular/router": { singleton: true, strictVersion: true }
121+
}
118122
})
119123
],
120124
};
@@ -154,11 +158,11 @@ Now, let's try it out!
154158
155159
2. After a browser window with the shell opened (``http://localhost:5000``), click on ``Flights``. This should load the microfrontend into the shell:
156160
157-
![Shell](shell.png)
161+
![Shell](https://github.com/angular-architects/module-federation-plugin/raw/main/packages/mf/tutorial/shell.png)
158162
159163
3. Also, ensure yourself that the microfrontend also runs in standalone mode at http://localhost:3000:
160164
161-
![Microfrontend](mfe1.png)
165+
![Microfrontend](https://github.com/angular-architects/module-federation-plugin/raw/main/packages/mf/tutorial/mfe1.png)
162166
163167
164168
Congratulations! You've implemented your first Module Federation project with Angular!

workspace.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
"packageJson": "packages/mf/package.json",
2929
"main": "packages/mf/src/index.ts",
3030
"assets": [
31+
{
32+
"input": "./packages/mf/tutorial",
33+
"glob": "**/*",
34+
"output": "tutorial"
35+
},
3136
"packages/mf/*.md",
3237
{
3338
"input": "./packages/mf/src",

0 commit comments

Comments
 (0)