DEV Community

Joel Marinho
Joel Marinho

Posted on

πŸš€ Exploring Microfrontends with Webpack Module Federation

Recently, I built a small project using Webpack Module Federation β€” a host app dynamically loading a remote React component (profile) β€” to better understand how microfrontends actually work in practice.

🧩 What Are Microfrontends?

Microfrontends bring the microservices mindset to the frontend.
Each part of the UI is an independent application β€” owned by separate teams, deployed separately, and composed into one seamless experience.

This architecture enables scalability, autonomy, and faster releases, especially in large organizations.

βš™οΈ Common Approaches

Module Federation (Webpack 5+)
β†’ Dynamically loads remote modules at runtime, sharing dependencies like React β€” no rebuilds or iframes.

Multi-Zone Architecture (Next.js)
β†’ Multiple Next.js apps stitched together through routing, ideal for domain-based segmentation.

Internal NPM Packages
β†’ Each microfrontend is versioned and shared as a private package β€” great control, but tighter coupling.

Iframes (the classic)
β†’ Offers full isolation and security, though with limited inter-app communication and styling flexibility.

🧠 How Remotes Work

A remote app exposes modules like this (for example the profile):

new ModuleFederationPlugin({
name: "profile",
filename: "remoteEntry.js",
exposes: { "./Profile": "./src/Profile.tsx" },
});

And the host dynamically loads it:

new ModuleFederationPlugin({
name: "container",
remotes: {
profile: "profile@http://localhost:3001/remoteEntry.js",
},
})
const Profile = React.lazy(() => import("profile/Profile"));

Webpack fetches remoteEntry.js, shares the React instance, and mounts the component β€” all at runtime.

βš–οΈ Trade-Offs to Consider

Deployment orchestration: independent deploys give flexibility, but require careful version control and CI/CD coordination.

Shared session state: managing auth and context across apps often needs shared cookies, tokens, or an API gateway.

Performance: multiple bundles add overhead β€” smart caching and lazy loading help keep things fast.

Consistency: design systems and routing conventions must be aligned across teams to avoid fragmentation.

Microfrontends aren’t a silver bullet β€” but they’re powerful when autonomy, scale, and parallel development matter.

If you’d like to see it in action, here’s the repos :
πŸ”— Host (Container): https://github.com/joel2011140/mfe-container
πŸ”— Remote (Profile): https://github.com/joel2011140/mfe-profile

I’d love your feedback β€” how are you handling deployment, communication, or shared state in your microfrontend setups?

frontend #microfrontends #reactjs #webdevelopment #javascript #modulefederation #webpack #softwarearchitecture #scalability #techcommunity #developerexperience #webapps

Top comments (0)