refactor(module-federation): consolidate getModuleFederationConfig implementations
Current Behavior
The getModuleFederationConfig function is implemented separately in 4 places with 70-80% duplicate code:
with-module-federation/webpack/utils.ts(161 lines)with-module-federation/rspack/utils.ts(150 lines)with-module-federation/angular/utils.ts- async version (~80 lines)with-module-federation/angular/utils.ts- sync version (~80 lines)
Each implementation repeats the same core logic:
- Get project from graph
- Get and filter dependencies
- Share workspace libraries and npm packages
- Apply eager packages
- Map remotes
Expected Behavior
A single shared implementation with framework-specific configuration via a FrameworkConfig interface. Each bundler utility becomes a thin wrapper that provides its specific configuration.
Changes
| File | Before | After | Change |
|---|---|---|---|
webpack/utils.ts |
161 lines | 54 lines | -107 lines |
rspack/utils.ts |
150 lines | 51 lines | -99 lines |
angular/utils.ts |
273 lines | 119 lines | -154 lines |
NEW module-federation-config.ts |
- | 289 lines | +289 lines |
Net reduction: 41 lines, with significantly improved maintainability
New Shared Utility
Created packages/module-federation/src/utils/module-federation-config.ts with:
FrameworkConfiginterface for bundler-specific customizationModuleFederationConfigResultinterface for type-safe return valuesgetModuleFederationConfigAsync()- for webpack/angular async configsgetModuleFederationConfigSync()- for rspack/angular sync configscreateDefaultRemoteUrlResolver()- shared remote URL generation- Caching for
NX_MF_DEV_SERVER_STATIC_REMOTESenv variable parsing (performance)
Benefits
- Single source of truth: Bug fixes and improvements only need to be made once
- Better maintainability: Framework-specific behavior is clearly separated via config
- Performance: Added caching for env variable parsing
- Type safety: New interfaces provide better IntelliSense and compile-time checks
- Backward compatible: All existing exports and behavior preserved
Related Issue(s)
N/A - This is a refactoring for improved code maintainability and performance.
Merge Dependencies
Must be merged AFTER: #33734
Deploy request for nx-docs pending review.
Visit the deploys page to approve it
| Name | Link |
|---|---|
| Latest commit | 9f32ad4f21af58cc403bd70fa2c02eb92d134f6a |
The latest updates on your projects. Learn more about Vercel for GitHub.
| Project | Deployment | Preview | Updated (UTC) |
|---|---|---|---|
| nx-dev | Preview | Dec 8, 2025 3:45am |
View your CI Pipeline Execution โ for commit 9f32ad4f21af58cc403bd70fa2c02eb92d134f6a
| Command | Status | Duration | Result |
|---|---|---|---|
nx affected --targets=lint,test,test-kt,build,e... |
โ Succeeded | 23m 6s | View โ |
nx run-many -t check-imports check-lock-files c... |
โ Succeeded | 2m 38s | View โ |
nx-cloud record -- nx-cloud conformance:check |
โ Succeeded | 11s | View โ |
nx-cloud record -- nx format:check |
โ Succeeded | 2s | View โ |
nx-cloud record -- nx sync:check |
โ Succeeded | <1s | View โ |
โ๏ธ Nx Cloud last updated this comment at 2025-12-12 12:47:25 UTC
This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.