The Microfrontend Revolution Module Federation with Angular

The Microfrontend Revolution Module Federation with Angular

15934fa2aa7b2ce21f091e9b7cffa856?s=128

Manfred Steyer

November 05, 2020
Tweet

Transcript

  1. @ManfredSteyer ManfredSteyer The Microfrontend Revolution Module Federation with Angular Manfred

    Steyer, ANGULARarchitects.io
  2. @ManfredSteyer

  3. @ManfredSteyer Micro Frontends

  4. @ManfredSteyer

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

    Module Federation #4: Version Mismatch #5: Possible Roadmap
  6. @ManfredSteyer Manfred Steyer

  7. @ManfredSteyer

  8. @ManfredSteyer

  9. @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!
  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

  14. @ManfredSteyer ?

  15. @ManfredSteyer Custom Builder

  16. @ManfredSteyer

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

    ng serve
  18. @ManfredSteyer

  19. @ManfredSteyer

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

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

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

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

  25. @ManfredSteyer

  26. @ManfredSteyer Dealing with Version Mismatches SemVer by Default: Highest compatiable

    version Fallback: Use own version Relaxing: Configure a range of accepted versions Singleton: Warning or error
  27. @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
  28. @ManfredSteyer Configuring Singletons shared: { "my-lib": { singleton: true, strictVersion:

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

    <11.1.1" } }
  30. @ManfredSteyer

  31. @ManfredSteyer Well … Webpack 5 is final! CLI 11 (RC)

    allows to opt into webpack 5 CLI 11 very soon
  32. @ManfredSteyer Free eBook ANGULARarchitects.io/book Updated for Module Federation and Alternatives

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

    Federated Angular Dynamic Federation Version Mismatches
  34. @ManfredSteyer d Slides & Examples Remote Company Workshops and Consulting

    http://angulararchitects.io