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

Micro Frontends with Module Federation: Beyond the Basics @w-jax 2021 München

Micro Frontends with Module Federation: Beyond the Basics @w-jax 2021 München

15934fa2aa7b2ce21f091e9b7cffa856?s=128

Manfred Steyer
PRO

November 11, 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 Version Mismatches #2 Dynamic Federation #3 Mono vs.

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

    Multirepo #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 Share Libs? Shell (Host) Microfrontend (Remote) shared:

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

    ng serve
  13. @ManfredSteyer

  14. @ManfredSteyer

  15. @ManfredSteyer Selecting the highest compatible version 10.0 10.1

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

  17. @ManfredSteyer • • • • • •

  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

  22. @ManfredSteyer

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

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

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

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

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

  29. @ManfredSteyer

  30. @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
  31. @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
  32. @ManfredSteyer

  33. @ManfredSteyer

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

  35. @ManfredSteyer

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

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

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

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

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

  41. @ManfredSteyer

  42. @ManfredSteyer

  43. @ManfredSteyer

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

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

  46. @ManfredSteyer Conclusion Baked-in Strategies for Version Mismatches Baked-in Strategies for

    Version Mismatches Webpack Runtime API: Dynamic Federation Webpack Runtime API: Dynamic Federation Monorepo vs. Multirepo: Self-restriction vs. (Costly) Freedom Monorepo vs. Multirepo: Self-restriction vs. (Costly) Freedom Frankenstein: Bootstrapping Several SPAs Frankenstein: Bootstrapping Several SPAs
  47. @ManfredSteyer d Slides & Examples Remote Company Workshops and Consulting

    http://angulararchitects.io