Webpack Module Federation and multi-frameworks

January 11, 2024 · View on GitHub

Intro

There's no code demo in this repo that shows how to create a shell app that consumes micro frontends from different frameworks using Webpack Module Federation. However, if you've read through the code demos than you have almost all the required knowledge to create one. The bits that weren't covered will be framework specific such as how to extend your framework's webpack configuration file.

This document gives you information on how you can have multiple frameworks working in a single application but beware of the following alert:

In his recent talk on Micro Frontend Anti Patterns, my friend Luca Mezzalira mentions using several frontend frameworks in one application.

There's a good reason for considering this an anti pattern: Current frameworks are not prepared to be bootstrapped in the same browser tab together with other frameworks or other versions of themselves. Besides leading to bigger bundles, this also increases the complexity and calls for some workarounds. However, Luca also explains that there are some situations where such an approach might be needed. He brings up the following examples: dealing with legacy systems, migration to a new UI framework/library, after merging companies with different tech stacks.1

Learn how to create multi-framework apps

If you're interested in multi-framework apps and want to learn more I advise you to study the following videos:

And articles:

More examples of multi-framework apps

You can find several examples of Webpack Module Federation setups, including setups using multiple frameworks, in the module-federation/module-federation-examples repo.

For other examples see the following Example 1 and Example 2 sections.

Example 1

The README for the @angular-architects/module-federation-tools package shows an example of how to use Webpack Module Federation in a multi-framework environment. The example can be seem live at https://red-ocean-0fe4c4610.azurestaticapps.net.

Module federation with multi-frameworks

The setup includes:

There's also a tutorial available for the above setup.

Example 2

Another example of a multi-framework setup can be found at manfredsteyer/multi-framework-micro-frontend. This example contains:

  • a shell in Angular 13.
  • a mfe1 app in Angular 13.
  • a mfe2 app in Angular 12.
  • a mfe3 app in Angular 12.
  • a mfe4 app in React 17.

Footnotes

  1. Taken from Pattern or Anti-Pattern? section of Multi-Framework and -Version Micro Frontends with Module Federation: Your 4 Steps Guide.