$30 off During Our Annual Pro Sale. View Details »

Import Maps: The Next Evolution Step for Micro Frontends? @w-jax 2022

Import Maps: The Next Evolution Step for Micro Frontends? @w-jax 2022

Manfred Steyer
PRO

November 10, 2022
Tweet

More Decks by Manfred Steyer

Other Decks in Programming

Transcript

  1. @ManfredSteyer Import Maps: The Next Evolution Step for Micro Frontends?

  2. @ManfredSteyer

  3. @ManfredSteyer

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

  5. @ManfredSteyer

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

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

  8. @ManfredSteyer

  9. @ManfredSteyer

  10. @ManfredSteyer

  11. @ManfredSteyer #1 Module Federation 101 #2 Import Maps #3 Module

    Federation on Import Maps
  12. @ManfredSteyer Manfred Steyer

  13. @ManfredSteyer

  14. @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')
  15. @ManfredSteyer Shell (Host) Microfrontend (Remote) RemoteEntry.js <script src="…"></script>

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

    shared: [ "@angular/core", "…" ]
  17. @ManfredSteyer Selecting the highest compatible version ^10.0 ^10.1

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

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

    10.1
  20. @ManfredSteyer shared: { "my-lib": { singleton: true, strictVersion: true //

    Error instead of warning! } } 11.0 10.1
  21. @ManfredSteyer

  22. @ManfredSteyer <script type="module"> import { format, parseISO } from 'date-fns';

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

    const date = parseISO('2022-08-15'); const weekday = format(date, 'EEE'); console.log(`It's a ${weekday}.`); </script>
  24. @ManfredSteyer <script type="importmap"> { "imports": { "date-fns": "./libs/date-fns.js" } }

    </script>
  25. @ManfredSteyer <script type="importmap"> { "imports": { "date-fns": "./libs/date-fns.js", "is-long-weekend": "http://this-app/module.mjs",

    "is-bridging-day": "http://that-app/module.mjs" } } </script>
  26. @ManfredSteyer <script type="importmap"> { "imports": { […] }, "scopes": {

    "http://that-app/module.mjs": { "date-fns": "./libs/other-date-fns.js" } } } </script>
  27. @ManfredSteyer const im = document.createElement('script'); im.type = 'importmap'; im.textContent =

    JSON.stringify(importMap); document.currentScript.after(im);
  28. @ManfredSteyer [https://caniuse.com/import-maps]

  29. @ManfredSteyer

  30. @ManfredSteyer

  31. @ManfredSteyer

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

  34. @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)
  35. @ManfredSteyer

  36. @ManfredSteyer

  37. @ManfredSteyer

  38. @ManfredSteyer

  39. @ManfredSteyer

  40. @ManfredSteyer

  41. @ManfredSteyer If you use webpack: No need to hurry. Stick

    with webpack Module Federation
  42. @ManfredSteyer If you use esbuild or vite: Give Native Federation

    a try and provide feedback
  43. @ManfredSteyer Once, Angular CLI supports esbuild: Give Native Federation a

    try and provide feedback
  44. @ManfredSteyer In general: Native Federation is your insurance for the

    mid- and long-term
  45. @ManfredSteyer Free eBook (5th Edition) ANGULARarchitects.io/book Module Federation & Nx

  46. @ManfredSteyer Module Federation: Mental Model rocks! Import Maps: Provide low

    level building blocks Native Federation: Insurance Try out with esbuild, vite, etc.
  47. @ManfredSteyer

  48. @ManfredSteyer d Slides & Examples Remote Company Workshops and Consulting

    http://angulararchitects.io