Micro-frontends with Module Federation
Build scalable micro-frontend architectures using Aurelia 2 with Webpack 5 Module Federation and Vite federation plugins.
Module Federation enables independent deployment and development of micro-frontends by allowing different Aurelia applications to share code and components at runtime. This guide covers implementing Module Federation with both Webpack 5 and Vite for maximum flexibility.
Understanding Module Federation
Module Federation allows you to:
Share components between Aurelia applications at runtime
Deploy independently without coordinating releases
Load modules dynamically from remote applications
Avoid code duplication across micro-frontends
Mix technology stacks (Aurelia with React, Vue, etc.)
Architecture Overview
Webpack 5 Module Federation
1. Install Dependencies
npm install webpack@5 webpack-cli webpack-dev-server html-webpack-plugin
npm install aurelia ts-loader html-loader2. Configure the Remote Application (Product App)
webpack.config.js:
3. Create Exposed Components
src/components/product-list.ts:
src/product-module.ts:
4. Configure the Host Application (Shell App)
webpack.config.js:
5. Dynamic Loading in Host Application
src/components/micro-frontend-loader.ts:
src/my-app.ts:
src/views/products-shell.html:
Vite Module Federation
1. Install Dependencies
2. Configure Remote Application
vite.config.ts:
3. Configure Host Application
vite.config.ts:
Advanced Patterns
Error Boundaries and Fallbacks
src/components/micro-frontend-boundary.ts:
Shared State Management
src/services/micro-frontend-state.ts:
Performance Optimizations
Preloading Remote Modules
Lazy Loading Strategy
Best Practices
1. Versioning Strategy
Use semantic versioning for shared dependencies
Pin major versions to avoid breaking changes
Test compatibility across micro-frontends
2. Development Workflow
3. Production Deployment
Deploy each micro-frontend independently
Use CDN for shared dependencies
Implement health checks for remote modules
Set up monitoring for failed module loads
4. Testing Strategy
Unit test components in isolation
Integration test the shell application
E2E test critical user journeys
Contract testing between micro-frontends
This Module Federation setup enables scalable micro-frontend architectures with Aurelia 2, supporting both Webpack 5 and Vite build systems while maintaining independent development and deployment capabilities.
Last updated
Was this helpful?