$30 off During Our Annual Pro Sale. View Details »
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
202403-WebComponent
Search
milkmidi
March 13, 2024
0
180
202403-WebComponent
milkmidi
March 13, 2024
Tweet
Share
More Decks by milkmidi
See All by milkmidi
202512-WebConfig 大 AI 時代,工程師的成長之路
milkmidi
0
0
WebComponent
milkmidi
1
3.2k
前端好朋友-tailwindcss
milkmidi
0
8.4k
202110-federation
milkmidi
0
150
Vue3一次就上手
milkmidi
0
6.3k
202007-React對戰雷台
milkmidi
0
190
Featured
See All Featured
Principles of Awesome APIs and How to Build Them.
keavy
127
17k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3k
Large-scale JavaScript Application Architecture
addyosmani
515
110k
The Invisible Side of Design
smashingmag
302
51k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.5k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
970
Six Lessons from altMBA
skipperchong
29
4.1k
Building a Modern Day E-commerce SEO Strategy
aleyda
45
8.3k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
9
1k
The Art of Programming - Codeland 2020
erikaheidi
56
14k
How To Stay Up To Date on Web Technology
chriscoyier
791
250k
Fireside Chat
paigeccino
41
3.7k
Transcript
如何發大財 Web Components 202403 - milkmidi
工 商服務 Senior Frontend Engineer Senior Backend Engineer Full stack
Engineer C++ / Android / iOS / Machine Learning / MIS Marketing Project Specialist Firmware Manager
milkmidi (奶綠茶) PositiveGrid Staff Frontend Engineer
[email protected]
https: / /
www.facebook.com/milkmidifans
Ten years ago!
jQuery Flash Action Script Silverlight RWD 是三 小 ! bootstrap
10 年前奶綠出過兩本書 已絕版 每年都要拿 Flash 出來鞭 一 下
Web Development Trends in 2024 React / Vue / Angular
Flash Action graphQL TailwindCSS webassembly Webpack / Vite No jQuery test e2e test 00940
我也想靠 Flash 吃 一 輩 子 呀 結果 Jobs 一
句話我就失業了
Why Web Component?
PM 要請你修改 sign-in 功能,這時你會 ?
jQuery 再戰 十 年
Vanilla.js
None
None
Web Component 是你的救贖
None
None
1 好找,好改 2 限縮 JS scope 3 準時下班
PM說: 現在要修改登出鈕按的 行 為。 不急, 十 分鐘後再給我就好
這時你要回答?
None
要使 用 前有個 But 人生 就是這個 But
None
How to use?
None
None
But! extends:’a’ Safari 支 援度太低
None
None
connectedCallback() Invoked when the custom element is first connected to
the document's DOM. disconnectedCallback() Invoked when the custom element is disconnected from the document's DOM. attributeChangedCallback() Invoked when one of the custom element's attributes is added, removed, or changed. Life cycle callbacks
attributeChangedCallback
奶綠發了個 PR <style> h1 { color: red; } </style>
Shadow DOM 與世隔絕的安全 小 屋 這我家的貓,很可愛吧 一 般的 HTMLElement 就可
用
None
外層和 Shadow DOM 的 style 不會互相影響 但,也是缺點 透過 attachShadow( {
mode } ); 可以讓外層的 JS 是否可以呼叫 shadowDOM 裡的元素 mode: open:element.shadowRoot // ShadowRoot obj mode: closed: element.shadowRoot // null
:host CSS pseudo class
None
外層如何更新 shadowDOM style?
1 透過 ::part
None
2 CSS Variable
None
3 ShadowRoot: adoptedStyleSheets 這個 支 援度 目 前還太低,先知道就好
Shadow DOM + slot 這我家的貓,很可愛吧
None
Q ? 此時會吃到的 style 是誰的 ?
slot with name
None
SEO ?
Shadow DOM SEO ?
shadowrootmode
None
WebComponent + React/Vue
WebComponent + React
WebComponent + React
React Modal
Modal
Modal
Modal
None
Web Component 就是這麼簡單
Micro Frontend
3個網站要共 用 Header
此時你會 ? iframe Federation Plugin(Webpack/Vite) WebComponent
Iframe 優:安全,style 也不會互吃 缺:慢、還是慢。
Federation Plugin 優:可以將共 用 的 package 抽出來 省下不必要的 k 數。
缺:要改架構,style 會互吃。
WebComponents 優: 一 隻 JS 就完美解掉。 缺:可能會做太快,讓 PM 誤以為這個 很簡單。
None
WebComponent + petite-vue
None
None
都是尤 大大 開發的 Only ~ 6kb DOM-based, mutates in place(not
virtual DOM) petite-vue
None
None
https://www.positivegrid.com/products/spark 實際應 用
None
WebComponent 限縮 scope petite-vue 處理阿雜的 DOM 事件 本來專案就走 SSR 的情況下,很適合導入
為何不使用 WebComponent + Vue
Q
工具沒有好或壞 用的好帶你上天堂 還是我家的貓,還是很可愛
學習不需要為公司、長官或同事, 不需要為別人,只為你自己。 五倍紅寶石-高見龍
QA
https://www.facebook.com/cmoneyengineer/photos https://www.facebook.com/groups/2616981278627207 圖片出處