DeveloperBreeze

Building Micro-Frontends with Webpack Module Federation (2025 Guide)

Introduction: Why Micro-Frontends in 2025?

As web applications grow larger and teams become more distributed, the traditional monolithic frontend architecture becomes harder to scale. Enter micro-frontends — the 2025-ready solution that brings backend microservices thinking to the frontend world.

Micro-frontends allow different teams to work independently on isolated UI components, which are then stitched together at runtime. This enables:

  • Faster deployment cycles
  • Independent scaling of frontend parts
  • Team autonomy across tech stacks (e.g., React, Vue, Angular)

At the core of this revolution is Webpack 5’s Module Federation Plugin, which allows independently deployed builds to share code dynamically.


What is Module Federation?

Module Federation is a feature in Webpack 5 that enables one JavaScript application (host) to dynamically load code from another (remote) at runtime.

Key Features:

  • Load remote components/apps on demand
  • Share dependencies to avoid duplication
  • Enable code splitting across teams
  • Works with different JS frameworks

Use Case Scenario

Let’s say you’re building a dashboard app in React, but your analytics module is handled by another team using Vue. You don’t want to tightly couple the two.

With Webpack Module Federation, you can load the Vue-based analytics micro-frontend into the React host — all without bundling it directly.


Project Structure Overview

We’ll build two apps:

  1. app-shell (Host) – React dashboard shell
  2. analytics-app (Remote) – Vue analytics micro-frontend
/app-shell         (React)
   webpack.config.js
   src/
       bootstrap.js

/analytics-app     (Vue)
   webpack.config.js
   src/
       main.js

Step 1: Setting Up the Remote App (Vue)

Install Vue + Webpack in the analytics-app:

npm init vue@latest
cd analytics-app
npm install

Install dependencies for Webpack configuration:

npm install -D webpack webpack-cli webpack-dev-server html-webpack-plugin

Create a webpack.config.js:

const HtmlWebpackPlugin = require('html-webpack-plugin');
const ModuleFederationPlugin = require('webpack').container.ModuleFederationPlugin;
const path = require('path');

module.exports = {
  mode: 'development',
  devServer: {
    port: 8081,
  },
  entry: './src/main.js',
  output: {
    publicPath: 'http://localhost:8081/',
  },
  plugins: [
    new ModuleFederationPlugin({
      name: 'analytics_app',
      filename: 'remoteEntry.js',
      exposes: {
        './Analytics': './src/components/Analytics.vue',
      },
      shared: require('./package.json').dependencies,
    }),
    new HtmlWebpackPlugin({ template: './public/index.html' }),
  ],
};

Step 2: Expose a Vue Component

Create src/components/Analytics.vue:

<template>
  <div class="analytics">
    <h2>Real-Time Analytics</h2>
    <p>This component is loaded remotely via Module Federation.</p>
  </div>
</template>

<script>
export default {
  name: 'Analytics',
};
</script>

Step 3: Set Up the Host App (React)

Now let’s set up the main container app.

npx create-react-app app-shell
cd app-shell
npm install -D webpack webpack-cli webpack-dev-server html-webpack-plugin

In webpack.config.js of app-shell:

const HtmlWebpackPlugin = require('html-webpack-plugin');
const ModuleFederationPlugin = require('webpack').container.ModuleFederationPlugin;
const path = require('path');

module.exports = {
  mode: 'development',
  devServer: {
    port: 8080,
  },
  entry: './src/bootstrap.js',
  output: {
    publicPath: 'http://localhost:8080/',
  },
  plugins: [
    new ModuleFederationPlugin({
      name: 'app_shell',
      remotes: {
        analytics_app: 'analytics_app@http://localhost:8081/remoteEntry.js',
      },
      shared: require('./package.json').dependencies,
    }),
    new HtmlWebpackPlugin({ template: './public/index.html' }),
  ],
};

Update src/bootstrap.js:

import('./App');

Update src/App.js:

import React from 'react';

// Lazy load the remote Vue component
const Analytics = React.lazy(() => import('analytics_app/Analytics'));

function App() {
  return (
    <div className="App">
      <h1>Host Dashboard</h1>
      <React.Suspense fallback={<div>Loading Analytics...</div>}>
        <Analytics />
      </React.Suspense>
    </div>
  );
}

export default App;

Step 4: Run Both Applications

Start the remote app (Vue):

cd analytics-app
npx webpack serve

Then start the host app (React):

cd app-shell
npx webpack serve

Visit http://localhost:8080 — you’ll see the React dashboard with the Vue analytics module seamlessly loaded via Module Federation.


2025 Best Practices for Micro-Frontends

Here are some crucial tips to future-proof your micro-frontend architecture in 2025:

Use Independent Deployments

Each micro-frontend should be versioned and deployed separately.

Handle Shared Dependencies Wisely

Use shared in Module Federation to prevent loading duplicate libraries (like react, vue, etc.).

Implement Design Tokens

Use a design system or tokens for consistent UI/UX across micro-apps.

Authentication & Routing

Use a centralized approach for auth tokens and route management — or pass them via shared context if needed.


Pros and Cons of Micro-Frontends with Module Federation

Pros:

  • Autonomous teams & deployments
  • Tech stack flexibility
  • Improved scalability
  • Faster build times for individual apps

Cons:

  • Increased complexity
  • More testing needed (integration)
  • SEO handling is trickier in client-rendered apps

SEO Considerations for Micro-Frontend Apps (2025 Update)

To improve Google indexing:

  • Use SSR (Server-Side Rendering) for public pages
  • Add <meta> tags and Open Graph data dynamically
  • Ensure Lighthouse scores are optimized (especially for CLS, LCP)
  • Avoid client-only routing for key landing pages

Conclusion

In 2025, micro-frontends are not just a buzzword — they are a proven way to scale modern frontend architectures. With Webpack Module Federation, teams can deliver independently developed features without sacrificing user experience or performance.

By following this guide, you’ve created a flexible, scalable frontend system that combines React and Vue in real time — powered by the magic of Webpack 5.


What’s Next?

  • Add a third micro-frontend (e.g., a user-profile module in Angular)
  • Deploy to cloud services (e.g., Vercel, Netlify, or AWS S3 + CloudFront)
  • Explore SSR with Next.js + Module Federation

Related Posts

More content you might like

Tutorial

How to Stop SSH From Timing Out

On your local machine, edit or create:

nano ~/.ssh/config

Aug 21, 2025
Read More
Tutorial

How to Translate URLs in React (2025 Guide)

For full SEO benefits in translated URLs:

Use a framework like Next.js for SSR with dynamic routes

May 04, 2025
Read More
Tutorial

Globalization in React (2025 Trends & Best Practices)

With mobile-first usage in emerging markets:

  • Ensure localized content fits small screens
  • Test RTL support on all breakpoints
  • Use dynamic font scaling for languages like Arabic or Hindi
  • Translate push notifications and in-app messages

May 04, 2025
Read More
Tutorial

Implementing Internationalization (i18n) in a Large React Application (2025 Guide)

In component:

const { t } = useTranslation('dashboard');

May 04, 2025
Read More

Discussion 0

Please sign in to join the discussion.

No comments yet. Be the first to share your thoughts!