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

Micro Frontends and Monorepos: Smart Idea or Contradiction?

Micro Frontends and Monorepos: Smart Idea or Contradiction?

15934fa2aa7b2ce21f091e9b7cffa856?s=128

Manfred Steyer
PRO

March 10, 2021
Tweet

Transcript

  1. @ManfredSteyer ManfredSteyer Micro Frontends and Monorepos: Smart Idea or Contradiction?

    Manfred Steyer, ANGULARarchitects.io
  2. @ManfredSteyer

  3. @ManfredSteyer Booking Booking Check-in Check-in Boarding Boarding Luggage Luggage Example

  4. @ManfredSteyer Micro Frontends

  5. @ManfredSteyer

  6. @ManfredSteyer Contents #1 Monorepo vs. Multirepo #2 Federated Angular #3

    Federation w/ Monorepos
  7. @ManfredSteyer Manfred Steyer

  8. @ManfredSteyer

  9. @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 Option 1: One App per Domain Monorepo
  10. @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 Option 2: One Monorepo per Domain Publish shared libs seperately via npm Repository n Repository 2 Repository 1
  11. @ManfredSteyer Benefits Autonomous Teams Separate Development Separate Deployment Own architecture

    decisions Own technology descisions
  12. @ManfredSteyer

  13. @ManfredSteyer

  14. @ManfredSteyer

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

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

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

  20. @ManfredSteyer ?

  21. @ManfredSteyer Custom Builder

  22. @ManfredSteyer

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

    ng serve
  24. @ManfredSteyer

  25. @ManfredSteyer

  26. @ManfredSteyer Tooling & Generator https://nrwl.io/nx

  27. @ManfredSteyer Scenario Separately deployed Just loaded once

  28. @ManfredSteyer

  29. @ManfredSteyer

  30. @ManfredSteyer Just one Version in Monorepo!

  31. @ManfredSteyer However … Deploy MFE1 Change Shared Lib Deploy MFE2

    Conflict?
  32. @ManfredSteyer Solution 1 (Prefered) Deploy all changed apps in release

    branch together!
  33. @ManfredSteyer Make Parsing in Build Process Easier

  34. @ManfredSteyer Solution 2a Deploy MFE1 Change Shared Lib v1.2 Deploy

    MFE2 Change Shared Lib v1.1 Share highest compatible version: v1.2
  35. @ManfredSteyer Solution 2b Deploy MFE1 Change Shared Lib v2.1 Deploy

    MFE2 Change Shared Lib v1.1 Conflict? Prevent with E2E tests!
  36. @ManfredSteyer Configuring // Required Version in app's webpack.config.js shared: {

    […] sharedMappings.getDescriptor('auth-lib', '^1.1'), } // Assign version number in lib's package.json "version": "1.2"
  37. @ManfredSteyer Current Pitfalls (working on it …) See npm page

  38. @ManfredSteyer

  39. @ManfredSteyer When can we have it? Webpack 5 and Module

    Federation: final Angular CLI 11: Experimental Opt-in for webpack 5 Angular CLI 12: Official webpack 5 integration
  40. @ManfredSteyer Free eBook ANGULARarchitects.io/book Updated for Module Federation and Alternatives

  41. @ManfredSteyer Conclusion Module Federation Loading Separately Deployed Code Micro Frontends

    Monorepo Always Deploy Changed Apps Or: Assign Versions
  42. @ManfredSteyer d Slides & Examples Remote Company Workshops and Consulting

    http://angulararchitects.io