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

Micro Frontends with Module Federation: Beyond the Basics @codecrafts2022

Micro Frontends with Module Federation: Beyond the Basics @codecrafts2022

15934fa2aa7b2ce21f091e9b7cffa856?s=128

Manfred Steyer
PRO

May 18, 2022
Tweet

More Decks by Manfred Steyer

Other Decks in Programming

Transcript

  1. @ManfredSteyer ManfredSteyer Micro Frontends with Module Federation: Beyond the Basics

    Manfred Steyer, ANGULARarchitects.io
  2. @ManfredSteyer Booking App Booking App Check-in App Check-in App Boarding

    App Boarding App Luggage App Luggage App
  3. @ManfredSteyer

  4. @ManfredSteyer

  5. @ManfredSteyer

  6. @ManfredSteyer const Component = await import('other-app/cmp');

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

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

    Federation #4 Multiple Frameworks/ Versions #0 Module Federation 101
  9. @ManfredSteyer Manfred Steyer

  10. @ManfredSteyer

  11. @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')
  12. @ManfredSteyer Shell (Host) Microfrontend (Remote) shared: [ "@angular/core", "…" ]

    shared: [ "@angular/core", "…" ]
  13. @ManfredSteyer 1) ng add @angular-architects/module-federation 2) Adjust generated configuration 3)

    ng serve
  14. @ManfredSteyer

  15. @ManfredSteyer

  16. @ManfredSteyer Selecting the highest compatible version 10.0 10.1

  17. @ManfredSteyer Conflict: No highest compatible version 11.0 10.1

  18. @ManfredSteyer shared: { "my-lib": { singleton: true } } 11.0

    10.1
  19. @ManfredSteyer shared: { "my-lib": { singleton: true, strictVersion: true //

    Error instead of warning! } } 11.0 10.1
  20. @ManfredSteyer shared: { "my-lib": { requiredVersion: ">=1.0.1 <11.1.1" } }

  21. @ManfredSteyer •Several options baked-in •However, best option: avoid conflicts upfront

  22. @ManfredSteyer

  23. @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
  24. @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
  25. @ManfredSteyer

  26. @ManfredSteyer

  27. @ManfredSteyer https://nrwl.io/nx

  28. @ManfredSteyer

  29. @ManfredSteyer Dynamic Module Federation Shell (Host) Microfrontend (Remote) remotes: {

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

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

    } exposes: { Cmp: './my.cmp.ts' } loadRemoteModule({ type: 'module', remoteEntry: 'http://…', exposedModule: './Cmp' })
  32. @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
  33. @ManfredSteyer

  34. @ManfredSteyer

  35. @ManfredSteyer const Component = await import('other-app/cmp');

  36. @ManfredSteyer const main = await import('other-app/main'); main.bootstrap();

  37. @ManfredSteyer const main = await import('other-app/main'); main.bootstrap(); const rootElm =

    document.createElement('app-root') document.body.appendChild(rootElm);
  38. @ManfredSteyer await import('other-app/main'); // Self-Bootstrapping const rootElm = document.createElement('app-root') document.body.appendChild(rootElm);

  39. @ManfredSteyer await import('other-app/main'); const rootElm = document.createElement('app-root') document.body.appendChild(rootElm); WrapperComponent

  40. @ManfredSteyer

  41. @ManfredSteyer

  42. @ManfredSteyer

  43. @ManfredSteyer https://red-ocean-0fe4c4610.azurestaticapps.net

  44. @ManfredSteyer Free eBook ANGULARarchitects.io/book Updated for Module Federation and Alternatives

  45. @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
  46. @ManfredSteyer d Slides & Examples Remote Company Workshops and Consulting

    http://angulararchitects.io