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
ES6ModulesとServiceWorker時代のTypescript開発
Search
Taketoshi Aono(青野健利 a.k.a brn)
June 15, 2017
Programming
0
150
ES6ModulesとServiceWorker時代のTypescript開発
ServiceWorkerとES6 Modulesを利用してTypescript開発をどう変えていけるか考えてみた
Taketoshi Aono(青野健利 a.k.a brn)
June 15, 2017
Tweet
Share
More Decks by Taketoshi Aono(青野健利 a.k.a brn)
See All by Taketoshi Aono(青野健利 a.k.a brn)
document.write再考
brn
6
2.9k
Parsing Javascript
brn
12
9k
JSON & Object Tips
brn
1
400
CA 1Day Youth Bootcamp for Frontend LT
brn
0
790
Modern TypeScript
brn
2
750
javascript - behind the scene
brn
3
680
tc39 proposals
brn
0
780
プロダクト開発とTypeScript
brn
8
2.8k
React-Springでリッチなアニメーション
brn
1
600
Other Decks in Programming
See All in Programming
watsonx.ai Dojo #4 生成AIを使ったアプリ開発、応用編
oniak3ibm
PRO
1
100
Tauriでネイティブアプリを作りたい
tsucchinoko
0
370
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
110
TypeScript Graph でコードレビューの心理的障壁を乗り越える
ysk8hori
2
1.1k
subpath importsで始めるモック生活
10tera
0
300
Duckdb-Wasmでローカルダッシュボードを作ってみた
nkforwork
0
120
Less waste, more joy, and a lot more green: How Quarkus makes Java better
hollycummins
0
100
Make Impossible States Impossibleを 意識してReactのPropsを設計しよう
ikumatadokoro
0
170
Quine, Polyglot, 良いコード
qnighy
4
640
NSOutlineView何もわからん:( 前編 / I Don't Understand About NSOutlineView :( Pt. 1
usagimaru
0
330
GitHub Actionsのキャッシュと手を挙げることの大切さとそれに必要なこと
satoshi256kbyte
5
430
Flutterを言い訳にしない!アプリの使い心地改善テクニック5選🔥
kno3a87
1
170
Featured
See All Featured
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
Teambox: Starting and Learning
jrom
133
8.8k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
109
49k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Scaling GitHub
holman
458
140k
Testing 201, or: Great Expectations
jmmastey
38
7.1k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Producing Creativity
orderedlist
PRO
341
39k
10 Git Anti Patterns You Should be Aware of
lemiorhan
654
59k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.7k
Done Done
chrislema
181
16k
Transcript
Typescript Development with ServiceWorker and ES6 Modules
せ: @brn (ꫬꅿ⨳ⵃa.k.a ـٕ٦ظ) 耵噟: ؿٗٝزؒٝسؒٝآص،٥iOSؒٝآص، ⠓爡: Cyberagent ،سذؙأةآؔRightSegment٥AI Messenger
ـؚٗ: http://abcdef.gets.b6n.ch/ Twitter: https://twitter.com/brn227 GitHub: https://github.com/brn
What is ServiceWorker? ServiceWorkerהכWebل٦آغحؙؚٓؐٝسד؝ٝزٗ٦ٕ׃ծ httpؙٔؒأزך؎ٝة٦إفز瘝➙תדjavascriptדכדֹזַֿה 㹋植ׅ堣腉דׅկ https://developers.google.com/web/fundamentals/getting-started/ primers/service-workers?hl=ja
Intercept http request ֿד➙㔐כServiceWorkerךhttpؙٔؒأز؎ٝة٦إفز堣腉הծ ES6 Modulesⵃ欽׃גTypescriptך如⚅➿涪橆㞮圓眠׃גת׃կ
ES6 Modules ֲ兛鸐ח⢪גְתׅ״י 涺ׁ㛇劤涸חכbabelדزٓٝأػ؎ٕ׃גְה䙼ְתׅկ ـٓؐؠדכ植㖈SafariהChrome Canarayד؟ه٦زׁגְתׅկ ➙㔐כֿךES6 Modulesⵃ欽׃גծ Typescriptךٌآُ٦ٕٗ٦س׃תׅկ
Typescript Compiler ـٓؐؠד⹛ֹתׅկ ׃ծCompilerHost鏣㹀ׅװ倯כ㢳ⴓئזךדծ ts.transpileModuleⵃ欽׃ג1ٌآُ٦ٕ嫣ח؝ٝػ؎ٕ׃תׅկ https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API#a-simple-transform-function
Strategy ؝ٝػ؎ٕך崧דָׅծ • ServiceWorkerךinstall؎كٝزskipWatingדׅ굲לׅ • ServiceWorkerךactivate؎كٝزclaimד㸣✪ׅկ • ً؎ٝ⩎כnavigator.serviceWorker.registerך䨱⦼ךPromiseⰻדactiveف ٗػذ؍湊鋔 •
activeחזtypescriptscript type="module"דٗ٦سׅկ • ServiceWorkerךfetch؎كٝزⰻד؝ٝػ؎ٕ׃ג鵤ׅկ הְֲ䠬ׄדװגת׃կ
tsconfig.json ׁח؝ٝػ؎ٕך鏣㹀tsconfig.jsonַ《⳿׃ֻזךדծ • 剑ⴱחً؎ٝأٖحس⩎ַpostMessageדtsconfigך《䖤䭷爙կ • tsconfigךٗ٦سָ㸣✪׃ServiceWorker⩎ַpostMessageד鸐濼 • typescriptךٗ٦س ה׃ת׃կ
Strategy ServiceWorkerכⴱ㔐ח؎ٝأز٦ׁٕהծinstall؎كٝزָ涪抟׃ծ waiting朐䡾חזתׅկ׃גٔٗ٦سׅהactive朐䡾ח獳遤׃ծ ✳䏝湡ך鏝㉏⟃꣬ծfetch؎كٝزٍؗحثֿׅהָ〳腉חזתׅկ install active ⴱ㔐 ✳㔐湡⟃꣬
Strategy ׃ַ׃ծ➙㔐כⴱ㔐ַل٦آ؝ٝزٗ٦ٕ׃ְկ זךדծself.skipWaiting()ㄎן⳿׃גactivate׃ծclaim()ㄎן⳿׃גծ ل٦آ؝ٝزٗ٦ٕ朐䡾ח׃תׅկ ل٦آך؝ٝزٗ٦ٕ朐䡾ָ㢌⻉ׅהծcontrollerchange؎كٝزָً ؎ٝل٦آדㄎן⳿ׁתׅկ ך؎كٝزٔحأٝ׃גֶֹծactive朐䡾嗚濼׃postMesseage דtsconfig.jsonך《䖤遤ְתׅկ install ⴱ㔐
active ⴱ㔐 skipWaiting controllerchange Main postMessage
Strategy register() controllerchange postMessage(load tsconfig) postMessage(load succeeded) load typescript via
script tag ... ServiceWorker Main install active skipWaiting() claim() wait fetch event load typescript via ES6 import transpileModule transpileModule Transpiled code
Demo رٌ https://brn.github.io/swts/
Problem 植㖈ךהֿES6 Modulesח㼎䘔׃גְזְModuleכ⹛⡲׃תׇկ את㣐⼱ךnpmךModuleכ⹛ַזְגֿהדׅկ ׃✲חⵃ欽ׅModule؝ٝػ؎ٕ׃גֶֽלזהַכז ַ׃תׇկ
GitHub ֿֿתדך㹋鄲npm moduleה׃גⰕ׃גֶֹת׃կ https://github.com/brn/swts.git
Summary ServiceWorkerדbabel٥typescriptכַז⦜זֿהָ㢳ְկ 暴חES6 Modulesָ⢪ִגծ commonjs䕎䒭ךٌآُ٦ָٕٗ٦سדֹזַהծ鼋欵ך㉏겗ָ֮կ commonjs => ES6 modulesַׅծamd٥Systemjsהְֲ鼋欵ח걾ַկ ES6
Modulesⵃ欽׃tranpileחꟼ׃גכתתװֿהָ㢳ֲկ
Summary ׀幠耮ָ֮הֲ׀ְׂת׃կ