Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
ng-japan meetup evolution of Angular Compiler
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Yosuke Kurami
October 10, 2017
Programming
1.2k
4
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
ng-japan meetup evolution of Angular Compiler
Yosuke Kurami
October 10, 2017
Transcript
54 slides
"OHVMBS$PNQJMFSͷਐԽ ng-japan meetup 2017 Autumn by @Quramy
About me
Today’s theme:
Today’s theme: Compile w "OHVMBSͷͷதͰϚχΞοΫͳ෦ྨ w Βͳͯ͘ࠔΒͳ͍ w WͷςʔϚͷҰͭ ޙड़
$PNQJMBUJPOJO"OHVMBS
Think about Component w ͜ͷ$PNQPOFOUͷϨϯμϦϯάɺͲ͏࣮͠·͔͢ʁ @Component({ selector: 'app', template: `
<span>{{count}}</span> <button (click)="countUp()">count up</button> `, }) export class AppComponent { count = 0; countUp() { this.count += 1; } }
Naive implementation Ҋ $PNQPOFOUͷߋ৽ͷʹɺ5FNQMBUFͷϓϨʔεϗϧ μΛஔͯ͠JOOFS)5.- function renderView(hostElement, component) { hostElement.innerHTML
= Component.template.replace('{{count}}', component.count); hostElement.querySelector('button') .addEventLister('click', () => component.countUp()); }
Naive implementation w ͜ͷํ๏৭ʑͳ͕ܽؕ͋Δɿ wඳըͷʹશཁૉͷ࡞Γସ͕͑ൃੜ͍ͯ͠Δ wඳըͷʹΠϕϯτϋϯυϦϯάΛొ͍ͯ͠͠Δ w ͙͢ʹ%0.ͷੑೳྼԽΛҾ͖ىͯ͜͠͠·͏
Little better way w ͏গ͠ਅ໘ʹॻ͍ͯΈΑ͏ function createView(hostElement, component) { //
create <span></span> const sp = span = document.createElement('span'); hostElement.appendChild(sp); // create <button></button> const btnText = document.createTextNode('count up'); const btn = document.createElement('button'); btn.addEventLister('click', () => component.countUp()); btn.appendChild(btnText); hostElement.appendChild(btn); } function updateView(hostElement, component) { hostElement.children[0].textContet = component.count; }
Little better way w %0.ૢ࡞Λ࠷খݶʹ͢Δ w %0.ཁૉͷ࡞࠷ॳͷҰճ͚ͩ w $PNQPOFOUͷঢ়ଶߋ৽࣌ มߋݕ࣮ߦ࣌
ɺผ్ VQEBUF༻ͷؔΛ࣮ߦ͢Δ
That’s all w "OHVMBS$PNQJMFS͕͍ͬͯΔ͜ͱҰॹ w 5FNQMBUFΛQBSTFͯ͠ɺEFpOF7JFXVQEBUF7JFX૬ Λ࡞ͬͯ͘ΕΔ w ͜ΕΒͷؔΛ·ͱΊͨͷ͕$PNQPOFOU'BDUPSZ
ngfactory in real world w ϒϥβ͔Β֬ೝ͢Δ͜ͱ ҰԠ Ͱ͖Δ
What Angular Compiler does w ϑϨʔϜϫʔΫͷཉٻ w ։ൃऀ 5FNQMBUFΛ༻͍ͯ એݴతʹ7JFXΛΈཱͯ
Δ͜ͱ͕Ͱ͖Δ w ϒϥβ࠷খίετͰ%0.πϦʔ͕ߋ৽͞ΕΔ w ͜ΕΒཱ͕྆Ͱ͖Δͷɺ$PNQJMFS͕ %0.Λૢ࡞͢ΔؔΛੜͯ͘͠Ε͍ͯΔ͔Β
What Angular Compiler does w 5FNQMBUFҎ֎ͷ$PNQJMFର w $44 w "OJNBUJPO
w %* QSPWJEFS *OKFDUBCMF w .PEVMF JNQPSUTFYQPSUTEFDMBSBUJPOʜ w 3PVUJOH
When Compiler works w ίϯύΠϥͷಈ࡞λΠϛϯά w +J5 +VTUJO5JNF ΞϓϦ͕࣮ߦ͞ΕΔλΠϛϯάͰղੳ
w "P5 "IFBEPG5JNF Ϗϧυ࣌ʹιʔείʔυΛ੩తʹղੳ
Using JiT Compilation import { enableProdMode } from '@angular/core'; import
{ platformBrowserDynamic } from '@angular/platform-browser- dynamic'; import { AppModule } from './app/app.module'; import { environment } from './environments/environment'; if (environment.production) { enableProdMode(); } platformBrowserDynamic().bootstrapModule(AppModule);
Using AoT Compilation import { enableProdMode } from '@angular/core'; import
{ platformBrowser } from '@angular/platform-browser'; import { AppModuleNgFactory } from './app/app.module.ngfactory'; import { environment } from './environments/environment'; if (environment.production) { enableProdMode(); } platformBrowser().bootstrapModuleFactory(AppModuleNgFactory); $ ngc # create app.module.ngfactory
"P5WT+J5
JiT Compilation’s problem w ϒϥβͰಈ࡞ͤ͞Δ·Ͱ$PNQJMFΤϥʔʹؾ͚ͳ͍ w MBOHVBHFTFSWJDF ΤσΟλͰܰݮՄೳ w $PNQJMFSͷηΩϡϦςΟϦεΫ
w 944Λಥ͔Εͨ߹ɺҙͷ$PNQPOFOUΛಈతʹ࡞ ͞ΕΔϦεΫʹ
AoT Compilation’s problem w Ϗϧυʹ͕͔͔࣌ؒΔ w $PNQPOFOUʹΑΔ͕ɺඵΦʔμʔΛཁ͢Δ ͜ͱ w KTͷαΠζ͕ංେԽ͕ͪ͠
w 7JFX&OHJOF dW ಋೖͰɺWYͱൺֱ͢Δͱ ఔʹαΠζ͕ݮ͞Ε͍ͯΔ
͍ͭ·Ͱ"P5WT+J5ͳͷ͔
V5 theme https://docs.google.com/presentation/d/ 17XEE7dNq2e8CAgC68vM7Hn_1hR5jwnPoBiRmqzAF9DQ/preview
V5 and Compilation w 4JNQMJDJUZͦͦ+J5ͱ"P5͕ࠞࡏ͍ͯ͠Δ࣌Ͱγ ϯϓϧͰͳ͍ w +J5Λ͏ཧ༝"P5͕͍͕ނ w Α͠ɺ"P5Λ͘͠Α͏ʂ
"P5CZEFGBVMUʹ͚ͯ
5SBOTGPSNFST#BTFE $PNQJMFS"1*
Transformer Based Compiler w ҰݴͰ͍͏ͱʮKTग़ྗํ๏ͷվྑʯ w ֖ͳ͍ݴ͍ํΛ͢Δͱɺʮ5ZQF4DSJQUຐվʯ
compiler-cli(<= 4.2.x) w 5SBOTGPSNFSಋೖҎલͷDPNQJMFSDMJ
compiler-cli(>= 4.3.0) w 5SBOTGPSNFSಋೖҎ߱ͷDPNQJMFSDMJ !BOHVMBSDMJW
Waste of intermediate files w ैདྷͷDPNQJMFSDMJͰதؒϑΝΠϧͱͯ͠ɺ OHGBDUPSZUTΛੜ͠ɺͦͷޙʹKTΛੜ͍ͯͨ͠ w தؒϑΝΠϧͷॻ͖ࠐΈɺதؒϑΝΠϧͷQBSTFίε τ͕༨ܭʹ͔͔ͬͯ͠·͏
Why generate dot ts ? w 5ZQF4DSJQUར༻্ͷ੍ w UTKTͷ%PXO5SBOTQJMFॲཧΛ֦ு͢ΔΈଘ ࡏ͍ͯ͠ͳ͔ͬͨ
Custom Transformers w 5ZQF4DSJQUWͰɺΦϦδφϧͷτϥϯεύΠϧ ॲཧ 5SBOTGPSNFS ΛՃͰ͖ΔΑ͏ʹͳͬͨ
What’s Transformer? w "45 நߏจ Λผͷ"45ม͢Δػߏ w #BCFMʹ͓͚ΔQMVHJOͷΑ͏ͳͷ w 5ZQF4DSJQUͷ෦ͰτϥϯεύΠϧॲཧͦΕͧΕͷ
5SBOTGPSNFSͱ࣮ͯ͠͞Ε͍ͯΔ w FH&4༻ &4༻ &4༻ 54ຊମ༻
Transformation example var square = x ** 2; <variable-statement> <variable-declaration-list>
<identifier escaped-text="square" /> <binary-expression> <identifier escaped-text="x" /> <asterisk-asterisk-token /> <first-literal-token text="2" /> </binary-expression> </variable-declaration-list> </variable-statement>
Transformation example <variable-statement> <variable-declaration-list> <identifier escaped-text="square" /> <call-expression> <property-access-expression> <identifier
escaped-text="Math" /> <identifier escaped-text="pow" /> </property-access-expression> <identifier escaped-text="x" /> <first-literal-token text="2" /> </call-expression> </variable-declaration-list> </variable-statement> var square = Math.pow(x, 2);
Compiler and Transformers w ʮOHGBDUPSZΛੜ͢Δ5SBOTGPSNFSʯΛDPNQJMFSDMJ ͕༻ҙ͢Δ͜ͱͰɺ"P5$PNQJMF͕ߴԽ
"OHVMBS#B[FM3VMF
What’s Bazel ?
What’s Bazel ? w (PPHMF͕࡞ɾެ։͍ͯ͠ΔϏϧυπʔϧ #MB[Fͱ͍͏(PPHMFશࣾͰΘΕ͍ͯΔπʔϧ͕ϕʔε w ʹWϦϦʔε༧ఆʢݱঢ়CFUBʣ w ༷ʑͳݴޠͷQSKʹରԠ
$$ HP +BWB 0CKFDUJWF$ 4DBMB 3VTU FUD
How to make compilation faster w #B[FMɺϏϧυରΛࡉԽ্ͨ͠Ͱɺରؒͷґଘ ؔΛར༻ͯ͠ϏϧυΛߴԽ͍ͯ͘͠
Parallel Compilation w ಠཱ͍ͯ͠ΔՕॴฒߦͯ͠$PNQJMFΛ࣮ߦ
Incremental Compilation w มߋ͕͋ͬͨՕॴͷΈ$PNQJMFΛ࣮ߦ
Bazel and dependency graph w 1BDLBHFؒͷґଘؔΛఆٛ͢Δ͜ͱͰ w ޓ͍ʹಠཱͨ͠1BDLBHFΛฒߦʹCVJMEͰ͖Δ w CVJMEࡁΈͷ1BDLBHFͷSFCVJMEΛεΩοϓͰ͖Δ
w ʮࡉ͔͘Ϗϧυʯ͢Δ͜ͱͰແବͳ$PNQJMFΛආ͚Δ w طଘͷϏϧυπʔϧͰ͍͏ͱɺNBLFHVMQʹ͍ۙ
Bazel and Angular w !BOHVMBSCB[FM w CFUB͔ΒϦϦʔε͞Ε͍ͯΔ w "OHVMBSͷNPEVMFΛ#B[FMͰϏϧυ͢ΔͨΊͷϧʔϧ ηοτ
w ෦తʹOHD DPNQJMFSDMJ Λ࣮ߦ͍ͯ͠Δ
@angular/bazel package(default_visibility = ["//visibility:public"]) load("@angular//:index.bzl", "ng_module") load("@io_bazel_rules_sass//sass:sass.bzl", "sass_binary") sass_binary( name
= "hello-world-styles", src = "hello-world.component.scss", deps = [ "//src/shared:colors", "//src/shared:fonts", ], ) ng_module( name = "hello-world", srcs = glob(["*.ts"]), deps = ["//src/lib"], assets = [":hello-world-styles"], tsconfig = "//src:tsconfig.json", )
How to use Bazel w #B[FMΛૉͰ͏ͷ໘ʜ w +BWB #B[FMͷηοτΞοϓ w
Ϗϧυఆٛ༻ͷݴޠ4LZMBSL 1ZUIPO Λ֮͑Δ w ݸผͷ3VMF BOHVMBS TBTT FUDʜ ͷ͍ํΛ֮͑Δ
@angular/cli w !BOHVMBSDMJ͕ରԠ͢ΔͷΛͭͷ͕٢ CB[FMCSBODI্Ͱ࡞ۀ͞Ε͍ͯΔ༷ w ରԠ͞Εͨ߹ɺCVJMEʹ+7.͕ඞཁ IUUQTHJUIVCDPNBMFYFBHMFOHDPOUBJOFSͷΑ͏ͳ %PDLFS*NBHFΛ$*Ͱར༻͢Δͱྑͦ͞͏
4VNNBSZ
Summary w "OHVMBS$PNQJMFS41"QMBUGPSNͱͯ͠ͷཁ w "P5ΛσϑΥϧτʹ͢ΔํͰண࣮ʹਐԽ͍ͯ͠Δ w 5SBOTGPSNFST#BTFE"1*#B[FM3VMF w !BOHVMBSDMJΛ࠷৽ʹอ͓ͬͯ͘͠
5IBOLZPV
"QQFOEJY" 5SBOTGPSNFSͰͲΕ͘Β͍ ͘ͳͬͯΔͷ͔
Compilation performance w ݸͷ$PNQPOFOUͷOHDʹཁ͢Δ࣌ؒ w DPNQJMFSDMJ!TFD w DPNQJMFSDMJ!SDTFD w ݮͱ͍͔ͳ͍·Ͱɺ༗ҙʹ͕ࠩग़Δ
"QQFOEJY# l"P5CZEFGBVMUzͷԸܙ
Easy to reproduce errors w Τϥʔͷ࠶ݱํ๏ڞ༗͕؆୯ʹ w ʮ+J5Ͱى͖ͳ͍͚Ͳɺ"P5ͰͷΈΤϥʔ͕ʜʯͱ͍͏ έʔεͰɺڞ༗͢Δଆݕূ͢Δଆେมɻ w
1MOLFSͰ"P5ͷڞ༗͕͍͠
Demonstration edit.ng
More Decks by Yosuke Kurami
See All by Yosuke Kurami
GraphQL の onError と Nullability のこれから
quramy
0
220
TypeScript LSP の今までとこれから
quramy
1
2.3k
フロントエンドテストの育て方
quramy
12
4k
App Router 悲喜交々
quramy
8
790
上手に付き合うコンポーネントテスト
quramy
6
2.4k
Patched fetch did not work
quramy
6
830
GraphQL あるいは React における自律的なデータ取得について
quramy
18
6k
Next.js App Router
quramy
15
4k
Fragment Composition of GraphQL
quramy
17
5k
Other Decks in Programming
See All in Programming
将来の標準フォーマッター?ktfmtを深堀る
t45k
0
220
まずはコードより業務と向き合う:テーブル解体のためにPdMを呼んだ話
sakawe_ee
0
260
はじめてのPLATEAU
nokonoko1203
1
660
作れるエンジニアから、価値を届けるエンジニアへ
ryunakayama
1
310
graphql-ruby を Spinel で速くしようとした話
mtsmfm
0
150
小さなアプリを作って公開するまで
onozaty
0
210
なぜ私たちは「現時点では」KMPの導入を見送ったのか
chigichan24
1
310
protojson における文字化けの扱い
kazuki1023
0
450
Getting Started with Vibe Coding
miccheng
0
240
Rails初心者がパスキーを実装してみて大変だったこと
ktombow
0
220
そのデザイントークン、Flutterでも同じ見た目になりますか?
nakamizu
0
440
Zero-Tap Sign-In対応、結局何をすればいいの?
mitohato14
0
2.5k
Featured
See All Featured
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
1k
Faster Mobile Websites
deanohume
310
32k
30 Presentation Tips
portentint
PRO
1
470
Paper Plane (Part 1)
katiecoart
PRO
3
12k
The Pragmatic Product Professional
lauravandoore
37
7.5k
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
320
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
The Mindset for Success: Future Career Progression
greggifford
PRO
0
560
Bash Introduction
62gerente
615
220k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
31k
Thoughts on Productivity
jonyablonski
76
5.5k
Why You Should Never Use an ORM
jnunemaker
PRO
61
10k