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

Micro Frontends with Angular: Module Federation Deep Dive @ngBe

Micro Frontends with Angular: Module Federation Deep Dive @ngBe

15934fa2aa7b2ce21f091e9b7cffa856?s=128

Manfred Steyer
PRO

December 15, 2020
Tweet

Transcript

  1. @ManfredSteyer ManfredSteyer Micro Frontends with Angular: Module Federation Deep Dive

    Manfred Steyer, ANGULARarchitects.io
  2. @ManfredSteyer

  3. @ManfredSteyer Booking App Booking App Check-in App Check-in App Boarding

    App Boarding App Luggage App Luggage App Micro Frontends
  4. @ManfredSteyer Micro Frontends

  5. @ManfredSteyer

  6. @ManfredSteyer Contents #1: Module Federation #2: Federated Angular #3: Dynamic

    Module Federation #4: Communication b/w MF #5 Version Mismatch #6: Multi Framework/ Version MF #7: Possible Roadmap
  7. @ManfredSteyer Manfred Steyer

  8. @ManfredSteyer

  9. @ManfredSteyer

  10. @ManfredSteyer Idea const Component = await import('http://other-app/xyz') Does not work

    with webpack/ Angular CLI Even lazy parts must be known at compile time!
  11. @ManfredSteyer Webpack 5 Module Federation Shell (Host) Microfrontend (Remote) //

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

    (Remote) RemoteEntry.js <script src="…"></script>
  13. @ManfredSteyer How to Share Libs? Shell (Host) Microfrontend (Remote) shared:

    [ "@angular/core", "…" ] shared: [ "@angular/core", "…" ]
  14. @ManfredSteyer

  15. @ManfredSteyer ?

  16. @ManfredSteyer Custom Builder

  17. @ManfredSteyer

  18. @ManfredSteyer 1) ng add @angular-architects/module-federation 2) Adjust generated configuration 3)

    ng serve
  19. @ManfredSteyer

  20. @ManfredSteyer

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

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

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

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

    } exposes: { Cmp: './my.cmp.ts' } loadRemoteModule({ remoteEntry: 'http://…', remoteName: 'mfe1', exposedModule: './Cmp' }) Helper Function using the Webpack API
  25. @ManfredSteyer

  26. @ManfredSteyer

  27. @ManfredSteyer Dealing with Version Mismatches SemVer by Default: Highest compatible

    version Fallback: Use own version Relaxing: Configure a range of accepted versions Singleton: Warning or error
  28. @ManfredSteyer Example for SemVer and Fallback • Shell: my-lib: ^10.0.0

    • MFE1: my-lib: ^10.1.1 • MFE2: my-lib: ^9.0.0 Result: • Shell and MFE1 share ^10.1.1 • MFE2 falls back to its own version ^9.0.0
  29. @ManfredSteyer However … • Shell: my-lib: ^10.0.0 • MFE1: my-lib:

    ^10.1.1 + MFE1: Dynamic Federation + Loading metadata too late Result: • Shell uses ^10.0.0 • MFE1 falls back to its own version ^10.1.1
  30. @ManfredSteyer However … • Shell: my-lib: ^10.1.1 • MFE1: my-lib:

    ^10.0.0 + MFE1: Dynamic Federation + Loading metadata too late Result: • Shell and MFE1 share ^10.1.1
  31. @ManfredSteyer Recommentation for Dynamic Federation Make sure, shell has highest

    versions Or: Load metadata upfront!
  32. @ManfredSteyer Configuring Singletons shared: { "my-lib": { singleton: true, strictVersion:

    true // Error instead of warning! } }
  33. @ManfredSteyer Relaxing Version Requirements shared: { "my-lib": { requiredVersion: ">=1.0.1

    <11.1.1" } }
  34. @ManfredSteyer

  35. @ManfredSteyer Key Idea Share a Lib with a Communication Service

    Message Passing? Separate Lib or Monorepo
  36. @ManfredSteyer

  37. @ManfredSteyer

  38. @ManfredSteyer Key Idea Expose Web Components via Module Federation However:

    Bundle Size & Workarounds
  39. @ManfredSteyer Example

  40. @ManfredSteyer

  41. @ManfredSteyer

  42. @ManfredSteyer

  43. @ManfredSteyer

  44. @ManfredSteyer Well … Webpack 5 is final! CLI is final

    However: webpack5/CLI integration is experimental! https://github.com/angular/angular-cli/pull/18873 See Pitfalls: https://tinyurl.com/y8e57ol9
  45. @ManfredSteyer Free eBook ANGULARarchitects.io/book Updated for Module Federation and Alternatives

  46. @ManfredSteyer Conclusion Module Federation Loading Separately Deployed Code Federated Angular

    Dynamic Federation Version Mismatches Multi Framework/ Version ?
  47. @ManfredSteyer

  48. @ManfredSteyer d Slides & Examples Remote Company Workshops and Consulting

    http://angulararchitects.io