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

Import Maps and Modern Hydration: The Future of Micro Frontends?

Import Maps and Modern Hydration: The Future of Micro Frontends?

Manfred Steyer
PRO

April 26, 2023
Tweet

More Decks by Manfred Steyer

Other Decks in Programming

Transcript

  1. @ManfredSteyer
    Import Maps and Modern Hydration
    The Future of Micro Frontends?
    ManfredSteyer

    View Slide

  2. @ManfredSteyer

    View Slide

  3. @ManfredSteyer

    View Slide

  4. @ManfredSteyer
    Booking App Check-in App
    Boarding App
    Luggage App

    View Slide

  5. @ManfredSteyer
    Benefits of Micro Frontends
    Peltonen, Mezzalira, and Taibi: Motivations, benefits, and issues for adopting Micro-Frontends: A Multivocal Literature Review

    View Slide

  6. @ManfredSteyer

    View Slide

  7. @ManfredSteyer
    const Component = await import('other-app/xyz')

    View Slide

  8. @ManfredSteyer
    const Component = await import('other-app/xyz')

    View Slide

  9. @ManfredSteyer

    View Slide

  10. @ManfredSteyer

    View Slide

  11. @ManfredSteyer

    View Slide

  12. @ManfredSteyer
    Technology-related Issues

    View Slide

  13. @ManfredSteyer

    View Slide

  14. @ManfredSteyer

    View Slide

  15. @ManfredSteyer
    #1
    Module Federation
    101
    #2
    Import Maps
    #3
    Module Federation
    on Import Maps
    #4
    Hydration for
    Micro Frontends

    View Slide

  16. @ManfredSteyer
    Manfred Steyer

    View Slide

  17. @ManfredSteyer

    View Slide

  18. @ManfredSteyer
    Shell (Host) Microfrontend (Remote)
    // Maps Urls in
    // webpack config
    remotes: {
    mfe1: "http://..."
    }
    // Expose files in
    // webpack config
    exposes: {
    './Cmp': './my.cmp.ts'
    }
    import('mfe1/Cmp')

    View Slide

  19. @ManfredSteyer
    Shell (Host) Microfrontend (Remote)
    RemoteEntry.js

    View Slide

  20. @ManfredSteyer
    Shell (Host) Microfrontend (Remote)
    shared: [
    "@angular/core", "…"
    ]
    shared: [
    "@angular/core", "…"
    ]

    View Slide

  21. @ManfredSteyer
    Selecting the highest compatible version
    ^10.0 ^10.1

    View Slide

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

    View Slide

  23. @ManfredSteyer
    shared: {
    "my-lib": {
    singleton: true
    }
    }
    11.0 10.1

    View Slide

  24. @ManfredSteyer
    shared: {
    "my-lib": {
    singleton: true,
    strictVersion: true // Error instead of warning!
    }
    }
    11.0 10.1

    View Slide

  25. @ManfredSteyer

    View Slide

  26. @ManfredSteyer
    <br/>import { format, parseISO } from 'date-fns';<br/>const date = parseISO('2022-08-15');<br/>const weekday = format(date, 'EEE');<br/>console.log(`It's a ${weekday}.`);<br/>

    View Slide

  27. @ManfredSteyer
    <br/>import { format, parseISO } from 'date-fns';<br/>const date = parseISO('2022-08-15');<br/>const weekday = format(date, 'EEE');<br/>console.log(`It's a ${weekday}.`);<br/>

    View Slide

  28. @ManfredSteyer
    <br/>{<br/>"imports": {<br/>"date-fns": "./libs/date-fns.js"<br/>}<br/>}<br/>

    View Slide

  29. @ManfredSteyer
    <br/>{<br/>"imports": {<br/>"date-fns": "./libs/date-fns.js",<br/>"is-long-weekend": "http://this-app/module.mjs",<br/>"is-bridging-day": "http://that-app/module.mjs"<br/>}<br/>}<br/>

    View Slide

  30. @ManfredSteyer
    <br/>{<br/>"imports": { […] },<br/>"scopes": {<br/>"http://this-app/module.mjs": {<br/>"date-fns": "./libs/this-date-fns.js"<br/>},<br/>"http://that-app/module.mjs": {<br/>"date-fns": "./libs/that-date-fns.js"<br/>}<br/>}<br/>}<br/>

    View Slide

  31. @ManfredSteyer
    const im = document.createElement('script');
    im.type = 'importmap';
    im.textContent = JSON.stringify(importMap);
    document.currentScript.after(im);

    View Slide

  32. @ManfredSteyer
    [https://caniuse.com/import-maps]

    View Slide

  33. @ManfredSteyer

    View Slide

  34. @ManfredSteyer

    View Slide

  35. @ManfredSteyer
    Meta Data
    • Providing at
    compile time
    • Loading at
    runtime
    Bundling
    • Remotes
    • Shared
    packages
    • Angular
    compiler
    Import Map
    • Generate using
    meta data
    • Scopes for
    version
    mismatches

    View Slide

  36. @ManfredSteyer

    View Slide

  37. @ManfredSteyer
    @gioboa/vite-module-federation
    @softarc/native-federation
    @angular-architects/native-federation yours
    Example: VanillaJS and React with esbuild
    Example: Vite with Svelte and Angular (AnalogJS)

    View Slide

  38. @ManfredSteyer

    View Slide

  39. @ManfredSteyer

    View Slide

  40. @ManfredSteyer

    View Slide

  41. @ManfredSteyer

    View Slide

  42. @ManfredSteyer
    Once, Angular CLI supports esbuild:
    Move to Native Federation

    View Slide

  43. @ManfredSteyer
    If you already use esbuild or vite:
    Native Federation

    View Slide

  44. @ManfredSteyer
    In general: Native Federation is your insurance for
    the mid- and long-term

    View Slide

  45. @ManfredSteyer
    Free eBook (5th Edition)
    ANGULARarchitects.io/book
    Module Federation & Nx

    View Slide

  46. @ManfredSteyer

    View Slide

  47. @ManfredSteyer
    HTML DATA
    FMP
    JS JS JS JS JS JS JS JS
    TTI

    View Slide

  48. @ManfredSteyer
    HTML DATA
    FMP
    JS JS JS JS
    TTI

    View Slide

  49. @ManfredSteyer
    isServer?
    Embed HTML Fragment from Micro Frontend
    else:
    Load (Web) Component via Module Federation

    View Slide

  50. @ManfredSteyer

    View Slide

  51. @ManfredSteyer
    Module
    Federation: Mental
    Model rocks!
    Import Maps:
    Provide low level
    building blocks
    Native
    Federation:
    Insurance
    Hydration via
    ProxyComp.

    View Slide

  52. @ManfredSteyer

    View Slide

  53. @ManfredSteyer
    d
    Slides & Examples Remote Company Workshops
    and Consulting
    http://angulararchitects.io

    View Slide