-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
590 lines (516 loc) · 20.1 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"
/>
<title>Micro Frontends</title>
<link rel="stylesheet" href="dist/reset.css" />
<link rel="stylesheet" href="dist/reveal.css" />
<link rel="stylesheet" href="dist/theme/codestar.css" />
<!-- Theme used for syntax highlighted code -->
<link rel="stylesheet" href="plugin/highlight/monokai.css" />
<style>
h1.deck-title {
transform: rotate(-2deg);
text-shadow: -4px 4px 1px black;
font-size: 12rem;
margin-bottom: 12rem;
}
.attribution,
.attribution a {
color: white;
font-size: 10px;
}
</style>
</head>
<body>
<div class="reveal">
<div class="slides">
<section data-markdown data-background-image="assets/buckyball-nyc.jpg" data-background-opacity="0.3" >
<textarea data-template data-line-numbers>
# Micro Frontends <!-- .element: class="deck-title" -->
source: <!-- .element: class="attribution" --> https://experiencenomad.com/leo-villareal-buckyball-buckminster-fuller-buckyballs/
Note:
* 1 hour interactive session
* brief overview followed by some examples
* Ask questions!
* (Assignments)
</textarea>
</section>
<section
data-background-image="assets/shot-by-cerqueira-0o_GEzyargo-unsplash.jpg"
>
<img src="assets/codestar_logo_dark_tagline.svg" width="40%" />
<br />
<br />
<div>
<img
style="display: inline-block; vertical-align: top; margin: 5px 0"
src="assets/github.svg"
width="5%"
/>
<div style="display: inline-block; vertical-align: top">
github.com/mdvanes
</div>
</div>
</section>
<section data-markdown>
<textarea data-template data-line-numbers>
## Micro _what_?
Note:
- First part also for back-end, last part more for front-end
- For back-end: what is monolith?
- Where is the threshold for a monolith?
- How do you prevent monolith? Solutions?
- Who is at a project that uses micro services? Why do they use it?
- Front-end: Who is (or has been) at a project with more than 10 devs? More than 50? More than 200?
- Back-end: How would you apply micro services to the front-end?
- Micro services vs Micro Frontends
- MFEs are: any range of solutions to integrate a collection of smaller frontends into one application (https://mdworld.nl/micro-frontends-in-a-nutshell)
- MFEs are not new
</textarea>
</section>
<section data-background-image="assets/page.svg" data-markdown>
<textarea data-template data-line-numbers>
Note:
- How would you build this?
- What are weak points of this solution?
</textarea
>
</section>
<section data-markdown>
<textarea data-template data-line-numbers>
[Go to order form](#)
Note:
Hyperlinks
* code is duplicated
* visible reloads when navigating
* no communication between micro apps
</textarea>
</section>
<section>
<div style="display: flex; justify-content: center">
<iframe
src="https://www.mdworld.nl"
style="width: 40%; height: 40vh"
></iframe>
<iframe
src="https://code-star.github.io/events"
style="width: 55%; height: 40vh"
></iframe>
</div>
<iframe
src="https://github.com/code-star"
style="width: 100%; height: 10vh"
></iframe>
<aside class="notes">
<p>iframes:</p>
<ul>
<li>needs special code to inject (404)</li>
<li>bottom: unsafe (clickjacking, frame-ancestors disabled)</li>
<li>isolation (e.g. Angular & React, or CSS classes)</li>
<li>limited responsive design</li>
</ul>
</aside>
</section>
<section data-background-color="#fefefe" data-markdown>
<textarea data-template data-line-numbers>
![Hyperlinks and Monolith diagram](assets/hyperlinks-and-monolith.svg)
Note:
- MFE types can and will be combined!
</textarea
>
</section>
<section data-background-color="#fdf6e3" data-markdown>
<textarea data-template data-line-numbers>
![Monolith Deployment Diagram](assets/monolith-deployment.drawio.svg)
Note:
- How (deployment) monoliths?
- Example, can be done in many ways
- Without registry (bash scripts, mono repo)
- Clearly defined responsibilities (testing, pipelines)
</textarea
>
</section>
<section data-background-color="#fefefe" data-markdown>
<textarea data-template data-line-numbers>
![Web Components Diagram](assets/web-components.svg)
Note:
- Micro vs Macro Web Components
- Angular Elements
- Shadow DOM
- Resource duplication (e.g. lodash in diagram)
</textarea
>
</section>
<section data-background-color="#fefefe" data-markdown>
<textarea data-template data-line-numbers>
![Module Federation Diagram](assets/module-federation.svg)
Note:
- Disadvantages are mentioned later in Demo slides (needs "webpack 5", immature libs, requires abstraction layer)
</textarea
>
</section>
<section data-markdown>
<textarea data-template data-line-numbers>
- hyperlinks
- iframes
- deployment monolith
- Web Components
- Module Federation
</textarea>
</section>
<section
data-markdown
data-background-image="assets/manfred-steyer.jpg"
style="text-shadow: 0px 0px 2px black"
>
<textarea data-template data-line-numbers>
# WWMSD? <!-- .element: style="text-shadow: 4px 4px 0 black; font-size: 15rem" -->
(What Would Manfred Steyer Do?) <!-- .element: class="fragment" -->
</textarea
>
</section>
<section data-markdown>
<textarea data-template data-line-numbers>
![microapps flowchart v1](assets/microapps-flowchart-v1.png)
- https://www.angulararchitects.io/en/aktuelles/a-software-architects-approach-towards/
</textarea
>
</section>
<section data-markdown>
<textarea data-template data-line-numbers>
![microapps flowchart v2](assets/microapps-flowchart-v2.svg)
Note:
- you don't want iframes
- instead of "Webpack 5?" you can also read "I want to deduplicate shared resources and to have easier navigation/state integration"
- Webpack alternatives (Rollup, Vite, esbuild), check MF support - Vite does! https://github.com/module-federation/module-federation-examples/blob/master/vite-react-simple/vite-react/vite.config.ts
</textarea
>
</section>
<section data-markdown data-background-color="#2f2f2f">
<textarea data-template data-line-numbers>
![component library in Storybook](assets/component-library.png)
Note:
- Familiar with Component Libraries/Storybook?
- Make sense to improve reusability of components
</textarea
>
</section>
<!-- <section data-background-color="#718aa4"></section> -->
<section>
<h2>Monorepos</h2>
<div style="display: flex; justify-content: center; gap: 4rem">
<img src="assets/yarn-logo.svg" width="20%" />
<img src="assets/lerna-hero.svg" width="20%" />
<img src="assets/nx-logo.svg" width="20%" />
</div>
<aside class="notes">
<p>Why Monorepos?</p>
<ul>
<li>What is a monorepo</li>
<li>Can contain multiple FE/BE apps</li>
<li>DX: don't have to link component library</li>
<li>DX: less toolchain maintenance (lint/jest)</li>
<li>Disadvantages:</li>
<li>Can be slow when misconfigured (also see Affected)</li>
<li>
Access control for teams between sub projects must be done by
only allowing MRs
</li>
</ul>
</aside>
</section>
<section data-markdown>
<textarea data-template data-line-numbers>
![Nx triangle](assets/nx-triangle.svg)
Note:
- And CLI/scaffolding
</textarea
>
</section>
<section>
<section>
<div style="display: flex; justify-content: center">
<iframe
src="https://code-star.github.io/nx-reference-portfolio/"
style="width: 80vw; height: 50vh"
></iframe>
</div>
</section>
<section data-markdown>
<textarea data-template data-line-numbers>
![Portfolio as a separate app](assets/nx-portfolio.png)
Note:
- (This is just a fallback for when site offline)
- Show that previous slide is live by using button
</textarea
>
</section>
<section data-markdown>
<textarea data-template data-line-numbers>
```ts []
// apps/portfolio/webpack.config.js
output: {
uniqueName: "portfolio",
publicPath: "auto",
},
...
plugins: [
new ModuleFederationPlugin({
name: "portfolio",
filename: "remoteEntry.js",
exposes: {
"./Module":
"apps/portfolio/src/app/remote-entry/entry.module.ts",
},
}),
],
```
Note:
- note "name" and "exposes"
- publicPath is path used for assets
- 'auto' uses e.g. self.location
</textarea
>
</section>
<section data-markdown>
<textarea data-template data-line-numbers>
```ts []
// src/index.ts
import('./bootstrap'); // Async!
// src/bootstrap.js
...
ReactDOM.render(<App/>, document.getElementById('root'));
// or for Angular in main.ts
import { platformBrowserDynamic } from
'@angular/platform-browser-dynamic';
platformBrowserDynamic().bootstrapModule(AppModule)
```
Note:
- Segue to explain bootstrap.js
- You will most of the time see such a bootstrapping "layer"
- async boundary for Webpack to produce a chunk that can be consumed with module federation
</textarea
>
</section>
<section data-markdown>
<textarea data-template data-line-numbers>
```ts []
// apps/portfolio/src/app/remote-entry/entry.module.ts
@NgModule({
declarations: [RemoteEntryComponent],
imports: [
BrowserModule,
UiModule,
RouterModule.forChild([
{
path: "",
component: RemoteEntryComponent,
},
]),
],
providers: [],
})
```
Note:
- Nothing special!
</textarea
>
</section>
</section>
<section>
<section>
<div style="display: flex; justify-content: center">
<iframe
src="https://code-star.github.io/nx-reference/iframe.html?id=appcomponent-v1-1-0--example&args=&globals=measureEnabled:false&viewMode=story#/portfolio"
style="width: 80vw; height: 50vh"
></iframe>
</div>
</section>
<section data-markdown>
<textarea data-template data-line-numbers>
![Nx Reference app in Storybook mode](assets/nx-storybook.png)
Note:
- (This is just a fallback for when site offline)
- Show that previous slide is live by using button
</textarea
>
</section>
<section data-markdown>
<textarea data-template data-line-numbers>
```ts []
// apps/demo/webpack.config.js
new ModuleFederationPlugin({
remotes: {
portfolio: `portfolio@http://localhost:4201/remoteEntry.js`,
},
}),
```
Note:
- This ("demo") is the shell app
</textarea
>
</section>
<section data-markdown>
<textarea data-template data-line-numbers>
```ts []
// apps/demo/src/app/app.module.ts
@NgModule({
...
imports: [
...
RouterModule.forRoot([{
path: "",
loadChildren: () =>
import("portfolio/Module").then(
(m) => m.RemoteEntryModule),},],
...
})
```
Note:
- Lazy import()
- Router
- path can be used to only load on specic routes
- In Angular with Router, in React with React.lazy()
- MF with everything possible, but with Nx, Angular is easiest
- Nx/Angular uses library from Manfred
</textarea
>
</section>
</section>
<section>
<div style="display: flex; justify-content: center">
<iframe
src="https://code-star.github.io/nx-reference-shell/"
style="width: 80vw; height: 50vh"
></iframe>
</div>
</section>
<section data-markdown>
<textarea data-template data-line-numbers>
```ts []
// apps/demo/webpack.config.js
const deps = require('./package.json').dependencies;
...
new ModuleFederationPlugin({
remotes: { ... },
shared: {
...deps,
"@angular/core": {
singleton: true,
requiredVersion: '12.2.11',
strictVersion: true },
...
```
Note:
- shared for deduplication (recall the lodash dep with macro web components)
- spread from package.json (this way the shell versions are leading)
- singleton for libs with shared global state
- strictVersion: rejects version if not requiredVersion (error, otherwise warning)
</textarea>
</section>
<section data-markdown>
<textarea data-template data-line-numbers>
- React MF with CRA
- https://github.com/module-federation/module-federation-examples/blob/master/cra/host/modulefederation.config.js
- https://github.com/module-federation/module-federation-examples/blob/master/cra/host/src/App.js
Note:
- MF adoption is improving. Support in CRA with CRACO
- With Nx, Angular MF is easiest. This is example with CRA without Nx
- Lerna + CRA + CRACO
- craco-module-federation plugin
</textarea>
</section>
<section data-markdown>
<textarea data-template data-line-numbers>
```
// app-01/src/pages/svelte-page.jsx
import loadApp from 'app_04/loadApp';
...
if (mountEl.current.innerHTML.length === 0) {
loadApp('app_04', name);
}
// app-01/webpack.config.js
app_04: 'app_04@http://localhost:3004/remoteEntry.js',
// app-04/webpack.config.js
exposes: {
'./App': './src/main.js',
'./loadApp': './src/loadApp.js',
},
// app-04/src/loadApp
const loadApp = (id, name) => {
return new App({
target: document.querySelector(`#${id}`),
props: { name },
});
};
```
Note:
- Svelte and Lit in React
- https://github.com/module-federation/module-federation-examples/blob/master/comprehensive-demo/app-01/src/pages/svelte-page.jsx
- mountEl + loadApp
- loadApp could be expanded to have callbacks to handle navigation/app state synchronisation!
- it is possible to always add this intermediate layer, but when host & remote both React, not needed.
</textarea>
</section>
<!-- <section data-markdown>
<textarea data-template data-line-numbers>
- React in Vue
- https://github.com/module-federation/module-federation-examples/blob/master/react-in-vue/layout/src/ReactButton.js
Note:
- This example uses React in the Vue shell to mount the component, but this is can be avoided
</textarea>
</section> -->
<section data-markdown>
<textarea data-template data-line-numbers>
- https://github.com/code-star/nx-reference
- https://mdworld.nl/micro-frontends-in-a-nutshell
- https://github.com/module-federation/module-federation-examples
Note:
- Nx repo with Module Federation from the examples before
- Overview article about Micro Frontends
- Plenty of MF examples
- Bi-directional (shell includes remote, remote includes from shell)
- Nested navigation / routing
- shared-context (React)
- Redux with injectReducer https://github.com/module-federation/module-federation-examples/tree/master/redux-reducer-injection
<!--
- DONE: Nx: MF for Angular AND SEPARATE TO THAT presets for React (so not MF!!) https://blog.nrwl.io/micro-frontends-using-module-federation-presets-for-react-and-storybook-typescript-compiler-4120cf134816 -->
</textarea>
</section>
</div>
</div>
<script src="dist/reveal.js"></script>
<script src="plugin/notes/notes.js"></script>
<script src="plugin/markdown/markdown.js"></script>
<script src="plugin/highlight/highlight.js"></script>
<script>
// More info about initialization & config:
// - https://revealjs.com/initialization/
// - https://revealjs.com/config/
Reveal.initialize({
hash: true,
progress: true,
controls: true,
// Disable controls bouncing animation
controlsTutorial: false,
// defaultTiming: false,
// slideNumber: "c/t",
// Learn about plugins: https://revealjs.com/plugins/
plugins: [RevealMarkdown, RevealHighlight, RevealNotes],
});
if (document.location.search === "?print-pdf") {
console.log("Preparing for printing");
Reveal.configure({
showNotes: "separate-page",
slideNumber: "c/t",
pdfSeparateFragments: false,
});
}
</script>
</body>
</html>