WhoBuilt

Module Federation

Nov 7, 2022· 1 h 3 min· 11K views·Watch on YouTube

Speakers

Zack Jackson, webpack maintainer and creator of Module Federation, and Paweł Trysła, creator of Re.Pack, discuss Module Federation for React Native on Callstack’s React Native Show podcast.

Re.Pack 3.0 and Module Federation

Trysła says Re.Pack 3.0 streamlines configuration with a single plugin and adds APIs and documentation for using Module Federation in React Native. Earlier versions could use Federation, but required substantial manual work.

Why Module Federation was created

Jackson traces the idea to the cost of distributing shared code through npm across more than 150 micro frontends. Nested package updates could take hours or days to reach the applications that needed them. Federation lets a webpack build load code from another build, aiming to support independent releases without burdening users with large duplicated bundles.

How remote loading works on mobile

Tryśla explains that Re.Pack resolvers tell the webpack runtime where to find remote containers and chunks, either from build-time configuration or at runtime. The native Script Manager fetches and evaluates the JavaScript, then connects it to webpack’s runtime. Jackson describes the asynchronous promise mechanism that lets applications choose a remote based on runtime information such as user access or an A/B test.

Mobile use cases and app store constraints

Jackson describes loading independently released parts of a large app, while Trysła emphasizes loading features on demand for users who need them. Trysła cautions that using Federation to replace or add features over the air can violate app store rules. He recommends keeping features available for review and using on-demand loading to optimize delivery.

Pitfalls and design choices

Jackson advises using Federation only when there is a clear business need, and warns that sharing whole packages can prevent tree-shaking and inflate bundles. He recommends checking bundle output and sharing only what needs to be shared, such as React when a single instance is required. Trysła adds that React Native teams should adopt it only when they have the expertise to measure and manage the result.

Takeaways

  • Use Module Federation when code delivery is slowing teams down or independent releases solve a real business problem.
  • Measure bundle size after configuration changes; sharing entire packages can pull in large amounts of unused code.
  • In React Native, use on-demand loading to manage app size while keeping features available for app review.
  • Keep federated modules self-sustaining and give them small, clear contracts with the host application.

Mentioned in this talk

Search inside this talk

What was claimed 15

Related talks