Skip to content

Commit 070f7fa

Browse files
committed
[Blog] [Ajay]: Module federation demo
1 parent c58979f commit 070f7fa

File tree

8 files changed

+108
-48
lines changed

8 files changed

+108
-48
lines changed

TestArena/Blog/Common/NavigationUtils/SiteMap.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ public static class SiteMap
6161
new("Module Federation in React",
6262
"/blog/module-federation-demo-in-react",
6363
new DateTime(2025, 4, 19),
64-
"images/blog/html-blogs/custom-element/banner.png",
65-
["micro-fronted", "react", "module-federation"], false),
64+
"images/blog/react/module-federation/banner.png",
65+
["micro-fronted", "react", "module-federation"]),
6666
];
6767
}
6868

TestArena/Blog/HtmlBlogs/CustomElement.razor

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@
1616
th {
1717
background-color: #f0f0f0;
1818
}
19-
.tip {
20-
background: #eaf4ff;
21-
padding: 10px;
22-
border-left: 5px solid #3498db;
23-
margin: 1em 0;
24-
}
2519
</style>
2620
@code{
2721
PageInfo currentPage = SiteMap.Pages.FirstOrDefault(x => x.RelativePath == "/blog/custom-elements-in-html");
@@ -49,7 +43,6 @@
4943
<CodeSnippet Language="html" ShowDescription="false">
5044
&lt;user-profile name="Alice" age="30"&gt;&lt;/user-profile&gt;
5145
</CodeSnippet>
52-
@* <pre><code>&lt;user-profile name="Alice" age="30"&gt;&lt;/user-profile&gt;</code></pre> *@
5346

5447
<p>This <code>&lt;user-profile&gt;</code> tag is not part of standard HTML. It's a <strong>custom element</strong> you can define with specific behavior and UI.</p>
5548

TestArena/Blog/React/ModuleFederationDemo.razor

Lines changed: 48 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22
@using TestArena.Blog.Common
33
@using TestArena.Blog.Common.NavigationUtils
44
<style>
5-
code, pre {
6-
background-color: #f4f4f4;
7-
padding: 0.5em;
8-
display: block;
9-
overflow-x: auto;
10-
}
115
table {
126
width: 100%;
137
border-collapse: collapse;
@@ -35,7 +29,7 @@
3529
</Header>
3630

3731

38-
<h1>Unleashing Micro Frontends with Module Federation in React</h1>
32+
<h2>Unleashing Micro Frontends with Module Federation in React</h2>
3933

4034
<p>
4135
Modern web applications are growing at an unprecedented scale. Codebases are expanding, teams are scaling, and release cycles are accelerating.
@@ -44,7 +38,7 @@
4438

4539
<p>Let’s break it down using the <strong>What</strong>, <strong>Why</strong>, <strong>When</strong>, and <strong>How</strong> format — so by the end, you’ll not only understand the concept but be motivated to give it a try in your next project.</p>
4640

47-
<h2>🧠 What is Module Federation?</h2>
41+
<h3>🧠 What is Module Federation?</h3>
4842

4943
<p>
5044
Module Federation is a feature introduced in <strong>Webpack 5</strong> that allows multiple independently-built and deployed applications (or “modules”) to share code and functionality with each other at runtime.
@@ -57,12 +51,15 @@
5751
</ul>
5852
</p>
5953

54+
<BlogImage Number="1" Description="Module Federation Integration architecture"
55+
ImagePath="/images/blog/react/module-federation/module federation.svg" />
56+
6057
<blockquote>
6158
🧩 <strong>Micro Frontends</strong>: An architectural approach where frontend applications are broken down into smaller, independently deployable apps that work together.<br>
6259
🔌 <strong>Webpack</strong>: A module bundler that packages JavaScript code for usage in a browser.
6360
</blockquote>
6461

65-
<h2>🚀 Why Should You Care About Module Federation?</h2>
62+
<h3>🚀 Why Should You Care About Module Federation?</h3>
6663

6764
<p>Imagine you're building a product with multiple teams:</p>
6865
<ul>
@@ -88,7 +85,7 @@
8885

8986
<p>It’s like giving every team their own spaceship — yet letting them dock with the mothership when needed 🚀</p>
9087

91-
<h2>📆 When Should You Use Module Federation?</h2>
88+
<h3>📆 When Should You Use Module Federation?</h3>
9289

9390
<p>Use Module Federation when:</p>
9491
<ul>
@@ -105,21 +102,23 @@
105102
<li>You don’t want the overhead of managing multiple repos and deployments</li>
106103
</ul>
107104

108-
<h2>🔧 How Does Module Federation Work?</h2>
105+
<h3>🔧 How Does Module Federation Work?</h3>
109106

110107
<p>Let’s explore using the GitHub repository: <a href="https://github.com/ajaysskumar/module-federation-demo" target="_blank">ajaysskumar/module-federation-demo</a></p>
111108

112-
<h3>🏗 Project Structure</h3>
113-
<pre><code>module-federation-demo/
109+
<h4>🏗 Project Structure</h4>
110+
<CodeSnippet Language="shell" Description="Running remote app">
111+
module-federation-demo/
114112
├── host-app/ # The main app consuming components
115113
└── remote-app/ # The app exposing components
116-
</code></pre>
114+
</CodeSnippet>
117115

118-
<h3>🔌 Step 1: Setup the Remote App</h3>
116+
<h4>🔌 Step 1: Setup the Remote App</h4>
119117
<p>The <code>remote-app</code> exposes a <code>FruitsTable</code> component.</p>
120118

121-
<h4>remote-app/webpack.config.js</h4>
122-
<pre><code>new ModuleFederationPlugin({
119+
<h5>remote-app/webpack.config.js</h5>
120+
<CodeSnippet Number="1" Language="js" Description="Running remote app">
121+
new ModuleFederationPlugin({
123122
name: "remoteApp",
124123
filename: "remoteEntry.js",
125124
exposes: {
@@ -134,11 +133,11 @@
134133
},
135134
},
136135
})
137-
</code></pre>
136+
</CodeSnippet>
138137

139-
<h4>remote-app/src/FruitsTable.js</h4>
140-
<pre><code>
141-
const FruitsTable = () => (
138+
<h5>remote-app/src/FruitsTable.js</h5>
139+
<CodeSnippet Number="2" Language="js" Description="FruitsTable remote component">
140+
const FruitsTable = () => (
142141
&lt;div&gt;
143142
&lt;h1 style={{ textAlign: "center", color: "green" }}&gt;Hello from Remote App component&lt;/h1&gt;
144143
&lt;table style={{ width: "50%", margin: "0 auto", borderCollapse: "collapse" }}&gt;
@@ -161,29 +160,34 @@
161160
&lt;/table&gt;
162161
&lt;/div&gt;
163162
);
164-
</code></pre>
163+
</CodeSnippet>
165164

166165
<p><strong>Run remote-app:</strong></p>
167-
<pre><code>cd remote-app
166+
<CodeSnippet Number="3" Language="shell" Description="Running remote app">
167+
cd remote-app
168168
npm install
169169
npm start
170-
# Runs at http://localhost:3002
171-
</code></pre>
170+
# Runs at http://localhost:3001
171+
</CodeSnippet>
172172

173-
<h3>🧲 Step 2: Consume in the Host App</h3>
173+
<h4>🧲 Step 2: Consume in the Host App</h4>
174174

175-
<h4>host-app/webpack.config.js</h4>
176-
<pre><code>new ModuleFederationPlugin({
175+
<h5>host-app/webpack.config.js</h5>
176+
<CodeSnippet Number="4" Language="js" Description="Module Federation Plugin setup in webpack config">
177+
new ModuleFederationPlugin({
177178
name: "host_app",
178179
remotes: {
179-
remote_app: "remote_app@http://localhost:3002/remoteEntry.js",
180+
remote_app: "remoteApp@http://localhost:3001/remoteEntry.js",
180181
},
181182
shared: { react: { singleton: true }, "react-dom": { singleton: true } },
182183
})
183-
</code></pre>
184+
</CodeSnippet>
184185

185-
<h4>host-app/src/App.js</h4>
186-
<pre><code>
186+
<BlogImage Number="2" Description="Remote js file"
187+
ImagePath="/images/blog/react/module-federation/Remote js file.png" />
188+
189+
<h5>host-app/src/App.js</h5>
190+
<CodeSnippet Number="5" Language="js" Description="Host app consuming remote component">
187191
import React, { Suspense, lazy } from "react";
188192

189193
const RemoteFruitsTable = lazy(() => import("remote_app/FruitsTable"));
@@ -197,18 +201,23 @@ npm start
197201
}
198202

199203
export default App;
200-
</code></pre>
204+
</CodeSnippet>
201205

202206
<p><strong>Run host-app:</strong></p>
203-
<pre><code>cd host-app
207+
<CodeSnippet Number="6" Language="shell" Description="Running host app">
208+
cd host-app
204209
npm install
205210
npm start
206-
# Runs at http://localhost:3001
207-
</code></pre>
211+
# Runs at http://localhost:3000
212+
</CodeSnippet>
208213

209214
<p>Boom! 🎉 The host renders a Fruits table from the remote app — without bundling it.</p>
210215

211-
<h2>🧠 Key Concepts at a Glance</h2>
216+
<BlogImage Number="3" Description="Remote component loading in host component"
217+
ImagePath="/images/blog/react/module-federation/Remote component loading in host component.png" />
218+
<p class="tip">💡 And the best part? You can update the remote app independently, and the host will always fetch the latest version at runtime.</p>
219+
220+
<h3>🧠 Key Concepts at a Glance</h3>
212221

213222
<table>
214223
<thead>
@@ -224,7 +233,7 @@ npm start
224233
</tbody>
225234
</table>
226235

227-
<h2>🔥 Final Thoughts — Why You Should Try Module Federation</h2>
236+
<h3>🔥 Final Thoughts — Why You Should Try Module Federation</h3>
228237

229238
<p>Module Federation isn’t just a tool — it’s a new way of thinking:</p>
230239
<ul>
@@ -239,7 +248,7 @@ npm start
239248

240249
<p>By adopting it, you're not only making your architecture more resilient — you're also unlocking a whole new level of collaboration and efficiency 🚀</p>
241250

242-
<h3>📎 Demo Repository</h3>
251+
<h4>📎 Demo Repository</h4>
243252
<p>Check out the complete working code:<br />
244253
<a href="https://github.com/ajaysskumar/module-federation-demo" target="_blank">
245254
🔗 ajaysskumar/module-federation-demo

TestArena/wwwroot/css/app.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,11 @@ a, .btn-link {
101101
code {
102102
color: #c02d76;
103103
}
104+
105+
106+
.tip {
107+
background: #eaf4ff;
108+
padding: 10px;
109+
border-left: 5px solid #3498db;
110+
margin: 1em 0;
111+
}
370 KB
Loading
619 KB
Loading
2.38 MB
Loading
Lines changed: 50 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)