Save 37% off PRO during our Black Friday Sale! »

Micro Frontends with Module Federation: Beyond the Basics @ijs2021 in Munich

Micro Frontends with Module Federation: Beyond the Basics @ijs2021 in Munich

15934fa2aa7b2ce21f091e9b7cffa856?s=128

Manfred Steyer
PRO

October 26, 2021
Tweet

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 const Component = await import('other-app/cmp');

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

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

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

  9. @ManfredSteyer

  10. @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')
  11. @ManfredSteyer How to Get the Microfrontend's URL? Shell (Host) Microfrontend

    (Remote) RemoteEntry.js <script src="…"></script>
  12. @ManfredSteyer How to Share Libs? 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 Dynamic Module Federation Shell (Host) Microfrontend (Remote) remotes: {

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

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

    } exposes: { Cmp: './my.cmp.ts' } loadRemoteModule({ remoteEntry: 'http://…', remoteName: 'mfe1', exposedModule: './Cmp' })
  19. @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
  20. @ManfredSteyer

  21. @ManfredSteyer

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

  25. @ManfredSteyer

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

  27. @ManfredSteyer

  28. @ManfredSteyer

  29. @ManfredSteyer Default Behavior Selecting the highest compatible version 10.0 10.1

  30. @ManfredSteyer Default Behavior Conflict: No highest compatible version 11.0 10.1

  31. @ManfredSteyer Example • Shell: my-lib: ^10.0 • MFE1: my-lib: ^10.1

    • MFE2: my-lib: ^9.0 • MFE3: my-lib: ^9.1 Result: • Shell and MFE1 share ^10.1 • MFE2 and MFE3 share ^9.1
  32. @ManfredSteyer Configuring Singletons shared: { "my-lib": { singleton: true }

    } 11.0 10.1
  33. @ManfredSteyer Configuring Singletons shared: { "my-lib": { singleton: true, strictVersion:

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

    <11.1.1" } }
  35. @ManfredSteyer

  36. @ManfredSteyer

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

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

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

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

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

  42. @ManfredSteyer

  43. @ManfredSteyer

  44. @ManfredSteyer

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

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

  47. @ManfredSteyer Conclusion Webpack Runtime API: Dynamic Federation Monorepo vs. Multirepo:

    Self-restriction vs. (Costly) Freedom Baked-in Strategies for Version Mismatches Frankenstein: Bootstrapping Several SPAs
  48. @ManfredSteyer d Slides & Examples Remote Company Workshops and Consulting

    http://angulararchitects.io