Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Micro Frontends with Module Federation: Beyond ...

Micro Frontends with Module Federation: Beyond the Basics @Architektur Tage 2022

Manfred Steyer

March 24, 2022
Tweet

More Decks by Manfred Steyer

Other Decks in Programming

Transcript

  1. @ManfredSteyer #1 Version Mismatches #2 Mono vs. Multirepo #3 Dynamic

    Federation #4 Multiple Frameworks/ Versions
  2. @ManfredSteyer #1 Version Mismatches #2 Mono vs. Multirepo #3 Dynamic

    Federation #4 Multiple Frameworks/ Versions #0 Module Federation 101
  3. @ManfredSteyer Shell (Host) Microfrontend (Remote) // Maps Urls in //

    webpack config remotes: { mfe1: "http://..." } // Expose files in // webpack config exposes: { './Cmp': './my.cmp.ts' } import('mfe1/Cmp')
  4. @ManfredSteyer How to Get the Microfrontend's URL? Shell (Host) Microfrontend

    (Remote) RemoteEntry.js <script src="…"></script>
  5. @ManfredSteyer Booking Booking Boarding Boarding Shared Shared Feature Feature Feature

    Feature Feature Feature Feature Feature Feature Feature … … … … … … … … … … … … … … … … … … Booking App Booking App Boarding App Boarding App Publish shared libs seperately via npm Repository n Repository 2 Repository 1 Version Mismatches? Strict Borders
  6. @ManfredSteyer Booking Booking Boarding Boarding Shared Shared Feature Feature Feature

    Feature Feature Feature Feature Feature Feature Feature … … … … … … … … … … … … … … … … … … Booking App Booking App Boarding App Boarding App
  7. @ManfredSteyer Dynamic Module Federation Shell (Host) Microfrontend (Remote) remotes: {

    mfe1: "http://..." } exposes: { Cmp: './my.cmp.ts' } import('mfe1/Cmp')
  8. @ManfredSteyer Dynamic Module Federation Shell (Host) Microfrontend (Remote) remotes: {

    } exposes: { Cmp: './my.cmp.ts' } loadRemoteModule({ type: 'module', remoteEntry: 'http://…', exposedModule: './Cmp' })
  9. @ManfredSteyer Dynamic Module Federation Shell (Host) Microfrontend (Remote) remotes: {

    } exposes: { Cmp: './my.cmp.ts' } loadRemoteModule({ type: 'module', remoteEntry: 'http://…', exposedModule: './Cmp' }) Helper Function using the Webpack API
  10. @ManfredSteyer const main = await import('other-app/main'); main.bootstrap(); const rootElm =

    document.createElement('app-root') document.body.appendChild(rootElm);
  11. @ManfredSteyer Conclusion Baked-in Strategies for Version Mismatches Baked-in Strategies for

    Version Mismatches Monorepo vs. Multirepo: Self-restriction vs. (Costly) Freedom Monorepo vs. Multirepo: Self-restriction vs. (Costly) Freedom Webpack Runtime API: Dynamic Federation Webpack Runtime API: Dynamic Federation Frankenstein: Bootstrapping Several SPAs Frankenstein: Bootstrapping Several SPAs