Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Angular Elementsで作るCustom Element
Search
ponday
May 24, 2018
Programming
0
290
Angular Elementsで作るCustom Element
俺の話を聞け!!LT大会 #9(2018/05/24)発表資料です。
ponday
May 24, 2018
Tweet
Share
More Decks by ponday
See All by ponday
関数型でGoFのデザインパターンやってみる
honda
1
1.2k
TypeScriptの型表現
honda
10
3k
Web Componentsの今
honda
1
410
これまでのReact、これからのReact
honda
0
300
Gatsbyお試し
honda
0
110
styled-components or emotion?
honda
0
670
Web ComponentsとAngular
honda
0
130
Atomic Design周りについての私見
honda
1
680
え、まだWeb Componentsを未来の技術だと思ってるの?
honda
2
790
Other Decks in Programming
See All in Programming
インプロセスQAにおいて大事にしていること / In-process QA Meetup
medley
0
110
파급효과: From AI to Android Development
l2hyunwoo
0
150
Browser and UI #2 HTML/ARIA
ken7253
2
160
Contribute to Comunities | React Tokyo Meetup #4 LT
sasagar
0
580
Bedrock×MCPで社内ブログ執筆文化を育てたい!
har1101
6
1.3k
Flutterでllama.cppをつかってローカルLLMを試してみた
sakuraidayo
0
110
Laravel × Clean Architecture
bumptakayuki
PRO
0
130
RuboCop: Modularity and AST Insights
koic
2
2.1k
プロフェッショナルとしての成長「問題の深掘り」が導く真のスキルアップ / issue-analysis-and-skill-up
minodriven
8
1.8k
Cursor/Devin全社導入の理想と現実
saitoryc
27
20k
Exit 8 for SwiftUI
ojun9
0
150
Ruby on Railroad: The Power of Visualizing CFG
ydah
0
270
Featured
See All Featured
Making Projects Easy
brettharned
116
6.1k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
30
2.3k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
30
2k
Building Adaptive Systems
keathley
41
2.5k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.2k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
29
9.4k
Visualization
eitanlees
146
16k
Producing Creativity
orderedlist
PRO
344
40k
Practical Orchestrator
shlominoach
187
11k
Site-Speed That Sticks
csswizardry
6
510
Rebuilding a faster, lazier Slack
samanthasiow
81
9k
The Invisible Side of Design
smashingmag
299
50k
Transcript
Angular Elementsで作るCustom Element 俺の話を聞け!!LT大会 #9 / May 24, 2018 ponday(@ponday_dev)
Profile Honda, Yusuke (@ponday_dev) 株式会社ベガコーポレーション エンジニア ng-fukuoka Like : TypeScript,
RxJS, Angular, Python, Kotlin 元々サーバサイド 趣味フロントエンドエンジニア 最近の仕事では画像処理とか機械学習とか お仕事あればお声掛けください!
Custom Elements ?
Custom Elements - WebComponentsの仕様の一つ - 自分で独自にHTMLタグが作れる - 以前発表した資料があるので説明はそちらに
(ご参考) WebComponentsの現在地 https://speakerdeck.com/honda/web-componentsfalsexian-zai-di
@angular/elements - Angularを利用してCustom Elementが作れる - コンポーネントではなく、AngularアプリをそのままCustom Element化
準備 ここまで通常のAngularプロジェクトと同じ
準備
ここからソースに手が入る
ソースを修正① AppModuleのデコレータ - 利用しないコンポーネントを削除 - bootstrap: [ … ]の表記を削除 -
entryComponentsを追加し、利用したいコンポーネントを記述
None
ソースを修正② AppModule - @angular/elementsからcreateCustomElementをインポート - Injector(@angular/core)をDI - ngDoBootstrapメソッドを作成 - Custom
Elementを生成して登録
None
None
None
ビルド ng build --prod --output-hashing=none 通常のビルドとコマンドは同じ ※ --output-hashingは必須ではない
ファイルを統合 - このままでも以下のファイルがあれば動く - main.js - polyfills.js - scripts.js -
runtime.js - 複数ファイルに分かれていると面倒なのでまとめる cat dist/elements-demo/{runtime,polyfills,scripts,main}.js > element.js
使ってみる - 生成したelement.jsを読み込み - customElement.defineで定義したタグ名でカスタムタグを配置 する
None
実行
良い点 - 普通のAngularアプリがほぼそのまま動かせる - 修正の大半はモジュールに対してなので、既存アプリも変換できるかも - Scoped CSSが使える - WebComponentsのみだとShadowDOM
がサポートされていないブラウザでは Scoped CSSできない - React, Vueとの共存も可能
微妙な点 - 容量が(かなり)大きい - サンプルで200KBくらい - 複数個のCustom Elementを読み込んでしまうと致命的かも - Ivyを使って容量削減に期待
- encapsulation: ViewEncapsulation.Nativeが相変わらず Shadow DOM v0っぽい(?) - Safariで動かなかった
Thank you !!