How leveraging native import map overrides can significantly benefit your micro frontend architecture
In this article, I am sharing about an architecture that has profoundly changed my perception of software development for large enterprises with complex infrastructure and team organization.
I’ve been eager to write this article for a long time, and now’s the time! I’ve always valued sticking to standards, and I believe the ecosystem is now ready to properly handle this architecture with the latest tools.
The advent of esbuild, the native support for ES Modules in browsers, the widespread adoption of import map, the emergence of tools like Native Federation, and the Nx ecosystem all combine to forge a flexible and well-maintained Micro Frontend Architecture.
I’ll cover:
· Real Story!
· A short reminder about browsers
· Micro frontend architecture in a nutshell
· What is an Import Map?
· Exploring the Full Potential of Import Maps and Overrides
· Nx Enables Scalable Micro Frontend Architecture
· What about Native Federation?
· Final Thoughts
Real Story!
Just to give you more context, I led the migration of several AngularJS applications to the newer Angular Framework. My client finally decided to make that move following the AngularJS deprecation announcement (stay up to date please 🙏)️.
Using the usual migration process was not possible. After investigating multiple scenarios, the micro frontend architecture was chosen. As we see, it facilitates incremental migration, provides isolation, and allows the integration of apps from multiple teams into one unified platform.
At that time, the micro frontend architecture was not yet popular and only the single-spalibrary was mature enough. It supports many frameworks, including AngularJS and Angular, making it a perfect choice for us!
Single-spa orchestrates the micro frontend by toggling between AngularJS or Angular implementations based on a feature flag:
Using single-spa has significantly enhanced my understanding of implementing micro frontend architecture, particularly highlighting the substantial benefits of utilizing import maps and micro frontend overrides. These tools have greatly improved my experience in local development, testing, and deployment.
I highly recommend having a look at the single-spa documentation to understand the concepts of micro frontend and import map.
A short reminder about browsers
To grasp the following subjects, I believe it’s crucial first to recall the basics of the web, focusing on the primary flow of a browser running a web application:
- The first action is always to get an
index.html
file, which has everything needed to start the application. - Then, the browser loads all the files that the
index.html
says it should. This often includes the main files for the application, like JavaScript and stylesheets. - After that, the application or the user interaction leads to more requests being made, for example, calling APIs or loading parts of the site as needed.
The browser’s job is simply to load these files or assets and put them together into the web application.
Micro frontend architecture in a nutshell
Let’s start with a short definition: the micro frontend architecture involves breaking down a frontend application into smaller, more manageable pieces — each responsible for a distinct feature or domain of your application. It’s often compared to the microservices concept but at the frontend layer.