feat(repack): builtin support for react-native deep imports for Module Federation #421
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Problem Statement:
In our current federated setup for React Native applications, a persistent issue emerged around the handling of shared dependencies, specifically with respect to deep imports from the 'react-native' library. These deep imports disrupted the efficient sharing of modules across federated boundaries. Furthermore, due to the challenges posed by these deep imports, our
assetsLoadercouldn't inline scaled assets in federated modules, leading to broken functionalities in some federated scenarios.References:
StackOverflow discussion on deep imports with Module Federation
Webpack's resolveMatchedConfigs
Solution:
This PR updates the
ModuleFederationPluginintroducing mechanisms to better handle these shared dependencies, and by extension, fixing theassetsLoaderissue.Changes Introduced:
Enhanced Configuration Options:
reactNativeDeepImports?: booleantoModuleFederationPluginConfigto allow the option to enable or disable adding React Native deep imports to shared dependencies.Deep Import Handling:
react-native/Libraries/Utilities/PixelRatio). This was achieved using an undocumented feature of webpack'sModuleFederationPlugin.react-nativelibrary and packages from the@react-nativegroup are correctly shared and resolved.With this setup, the PR description begins by setting the context and outlining the problem, then presents the solution and the steps taken to achieve it.
Test plan
ModuleFederationPlugin.test.ts