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

How to build Micro Frontends with @angular/elements

Marcell Kiss
February 02, 2022

How to build Micro Frontends with @angular/elements

How to build Micro Frontends with @angular/elements
Using Web Components / Custom Elements

Was presented on Angular Meetup Hungary [EN] and on Angular Meetup Graz [DE] in 2022

Demo: https://github.com/marcellkiss/angular-web-component-example

Marcell Kiss

February 02, 2022
Tweet

More Decks by Marcell Kiss

Other Decks in Education

Transcript

  1. Frontend Structure Nx Workspace - Smart, Fast and Extensible Build

    System - apps - change portal - libs - address - payment - search - shared @change-portal/search Change portal Address Payment Search Shared
  2. UX Flow Change Address Change Payment Method Change Search Settings

    Enter your Address… Continue Home Edit Save Continue Con f irm Feedback ZIP City Address: Universitätspl. 3, ZIP: 8010 City: Graz Back Changes are saved address lib /address/edit /address/con f irm /address/feedback
  3. Mobile Integration • Integration via URL 
 (in-app browser) •

    Authenticaton via SSO • Same look and feel Do X Do Y Change Address Main Menu Enter your Address… Continue Edit ZIP City Https://change-portal.com/address/edit …
  4. Scaling to this… Frontend Interaction Service Address Service Payment Service

    Search Service Frontend Frontend Interaction Service Interaction Service
  5. Motivations • Scalability • Robustness • Framework agnostic • Smaller,

    less complex codebase • Independent, specialized teams • Independent 
 development / tests / deployment …faster development…
  6. Implementation approaches to evaluate • Build Time Integration • URL

    • Iframe • Web Components • … Server Side Template Composition, JavaScript
  7. Challenges to overcome • Performance • Payload Size • Communication

    (Fragments <-> Host) • Versioning • Test Environment • Governance complexity
  8. Payload Size Angular Address Angular Payment Angular Search Big Portal

    Address Angular Payment Search Module Federation by Webpack 5
  9. Versioning Design System Address Payment Search The Big Portal @latest

    @latest @latest @latest @latest @latest @latest
  10. Versioning Design System Address Payment Search The Big Portal @2.0.0

    @latest @latest @latest @1.8.2 @1.8.2 @1.8.2
  11. What’s this? Angular Component @angular/ elements Web Component bundle.js <html>

    
 … 
 <angular-component></angular-component> 
 … 
 </html> MainApp Selector: ‘angular-component’
  12. Build Process ng update ngx-build-plus --force Ng build before Ng

    build after angular.json Credits: Manfred Steyer
  13. Summary Project • Team • Product • Architecture • Mobile

    Integration • Scaling Micro Frontends • The Vision • Motivations • Approaches • Challenges • Versioning @angular/elements • CustomElementRegistry • Example Repo • Inputs / Outputs • Routing • Build Process
  14. Resources - [Book] Micro Frontends in Action by Michael Geers

    
 https://micro-frontends.org/ 
 - [Article] Micro Frontends by Martin Fowler 
 https://martinfowler.com/articles/micro-frontends.html 
 - [Docs] Web Components by MDN 
 https://developer.mozilla.org/en-US/docs/Web/Web_Components - [Docs] @angular/elements 
 https://angular.io/guide/elements 
 - [OSS] ngx-build-plus 
 https://github.com/manfredsteyer/ngx-build-plus#readme 
 - [OSS] Angular Elements Example with nx workspace 
 https://github.com/marcellkiss/angular-web-component-example 
 - [OSS] Angular Module Federation 
 https://github.com/angular-architects/module-federation-plugin - [Presentation] Frontend Monoliths: 
 https://www.slideshare.net/JonasBandi/frontend-monoliths-run-if-you-can-137391467