Slide 1

Slide 1 text

Marcell Kiss, 2022 From Angular Apps to Micro Frontends with @angular/elements

Slide 2

Slide 2 text

About me Marcell Kiss Frontend Contractor @martzellk @marcellkiss

Slide 3

Slide 3 text

Overview The Project Micro Frontends @angular/elements

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

The Project

Slide 6

Slide 6 text

The Team Product Owner Scrum Master Business Analyst UI/UX Designer Fullstack Developer

Slide 7

Slide 7 text

The Product Change 
 payment method Change 
 search settings Change 
 address

Slide 8

Slide 8 text

The Architecture Frontend Interaction Service Address Service Payment Service Search Service

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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 …

Slide 12

Slide 12 text

Is this a Micro Frontend?

Slide 13

Slide 13 text

Scaling …from this Frontend Interaction Service Address Service Payment Service Search Service

Slide 14

Slide 14 text

Scaling to this… Frontend Interaction Service Address Service Payment Service Search Service Frontend Frontend Interaction Service Interaction Service

Slide 15

Slide 15 text

Micro Frontends

Slide 16

Slide 16 text

The Big Portal Frontend: SPA (Angular) to rule them all…

Slide 17

Slide 17 text

Motivations • Scalability • Robustness • Framework agnostic • Smaller, less complex codebase • Independent, specialized teams • Independent 
 development / tests / deployment …faster development…

Slide 18

Slide 18 text

Implementation approaches to evaluate • Build Time Integration • URL • Iframe • Web Components • … Server Side Template Composition, JavaScript

Slide 19

Slide 19 text

Challenges to overcome • Performance • Payload Size • Communication (Fragments <-> Host) • Versioning • Test Environment • Governance complexity

Slide 20

Slide 20 text

Payload Size Angular Address Angular Payment Angular Search Big Portal

Slide 21

Slide 21 text

Payload Size Angular Address Angular Payment Angular Search Big Portal Address Angular Payment Search Module Federation by Webpack 5

Slide 22

Slide 22 text

Versioning Address Payment Search The Big Portal @latest @latest @latest

Slide 23

Slide 23 text

Versioning Design System Address Payment Search The Big Portal @latest @latest @latest @latest @latest @latest @latest

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

@angular/elements

Slide 26

Slide 26 text

What’s this? Angular Component @angular/ elements Web Component bundle.js 
 … 
 
 … 
 MainApp Selector: ‘angular-component’

Slide 27

Slide 27 text

De f ine Custom Element npm install @angular/elements --save

Slide 28

Slide 28 text

Example Repo angular-web-component-example https://github.com/marcellkiss/angular-web-component-example Try it on Vercel!

Slide 29

Slide 29 text

Npm run start MainApp WcApp http://localhost:4200 http://localhost:4210/main.js selector: ‘wc-app’

Slide 30

Slide 30 text

Communication: I/O WcApp Main App

Slide 31

Slide 31 text

Routing Address Web-Component mainApp http://localhost:4200/web-component-host/view [route]=‘/view’ routeChange.emit(’/edit’) Routing Logic

Slide 32

Slide 32 text

Build Process ng update ngx-build-plus --force Ng build before Ng build after angular.json Credits: Manfred Steyer

Slide 33

Slide 33 text

Package Size

Slide 34

Slide 34 text

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

Slide 35

Slide 35 text

Questions and Answers Thanks for listening!

Slide 36

Slide 36 text

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