EcmaScriptèšèªã®æŽå²ã¯ããã©ãŠã¶ãŒã®åçŽãªã¹ã¯ãªããèšèªãããããŸããŸãªãã¹ãç°å¢ã§åäœããææ°ã®æ±çšèšèªã«ãŸã§åã³ãŸãã èšèªã®è€éããšãšãã«ãã¢ãžã¥ãŒã«æ§é ãæŽçããã©ã€ãã©ãªã«é 眮ããŠã³ãŒããåå©çšããå¿ èŠæ§ãçããŸããã æåã®ã©ã€ãã©ãªã¯ã察å¿ããJSãã¡ã€ã«ããããã€ããŒã®ãã¹ããŸãã¯CDNããèªã¿èŸŒãããšã«ãã£ãŠã€ã³ããŒããããçžäºäœçšã¯ãååãšããŠãæ¢ç¥ã®ååãæã€é¢æ°ãšã¯ã©ã¹ãã°ããŒãã«ã¹ããŒã¹ïŒãŠã£ã³ããŠãªããžã§ã¯ãïŒã«ãšã¯ã¹ããŒãããããšã«ãã£ãŠå®è¡ãããŸããã
ãã®ã¹ããŒã ã¯é·ãé䜿çšãããŠãããåçŽãªã±ãŒã¹ã§ã¯éåžžã«ããŸãæ©èœããŸãã
å°é£ã¯ãã©ã€ãã©ãªãå€ãããŠã©ã€ãã©ãªéã®é¢ä¿ãå§ãŸã£ããšãã«å§ãŸããŸãããŸããã°ããŒãã«ãã¹ããªããžã§ã¯ããè©°ãŸã£ãŠãããæ¥ç¶ãããŠãããã¹ãŠã®ã©ã€ãã©ãªã¯ã競åããªãäžæã®ååãã€ã³ããŒãããå¿ èŠããããŸãã 第äºã«ãã©ã€ãã©ãªéã®çžäºéçšæ§ãšåå©çšãä¿èšŒããæ瀺çãªæ¹æ³ã¯ãããŸããã
ãã¹ããããäŸåé¢ä¿ã®åé¡ã¯ãDOMã¢ãã«ã®
dynamic <script> injection
ã䜿çšããŠè§£æ±ºã§ããã°ããŒãã«ãã¹ããªããžã§ã¯ãã®æ¢ç¥ã®ååã§ãšã¯ã¹ããŒãããããšã§åå©çšã§ããŸãããããã¯æ®éçãªãœãªã¥ãŒã·ã§ã³ã§ã¯ãªããã©ã€ãã©ãªäœæè éã®æé»çãªåæã«åºã¥ããŠæ§ç¯ãããã¯ã©ã€ã¢ã³ãã¹ã¯ãªããã éšåçã«ã
query string
ã§ãã©ã¡ãŒã¿ãŒãCDNãµãŒããŒã«æž¡ããããŒããããJSã©ã€ãã©ãªã®åå空éãæå®ããããšã§åå解決ã解決ããŸããããããæ®éçã§ã¯ãããŸããã
éåæã®èªã¿èŸŒã¿ãšDOMã¢ãã«ãšã®çžäºäœçšã«é¢é£ããããã€ãã®åºæ¬çãªåé¡ãæ®ã£ãŠããŸãã åŸè ãåè ã«äŸåããŠããå Žåãäžéšã®ã©ã€ãã©ãªã¯ä»ã®ã©ã€ãã©ãªããå ã«ããŒãããå¿ èŠããããŸãã åçã€ã³ããŒãã®å Žåãããã«ã¯ããã³ããŒãšãã©ãŠã¶ã®ããŒãžã§ã³ã«å¿ããŠãéåæãã©ã°ã®æ£ããèšå®ãŸãã¯
readystatechanged
ã€ãã³ãã®æäœãå¿ èŠã§ãã
ãã¡ããããã®äžè¬çãªå Žåã«ã¯ãèšäºã§èª¬æãããŠãã解決çããããŸã ã ãã ãããŸããããŠã³ããŒãå¯èœãªãã¹ãŠã®ã©ã€ãã©ãªã®äŸåé¢ä¿ãæ éã«ç£èŠããå¿ èŠããããŸãã次ã«ãäžéšã®ã©ã€ãã©ãªãDOMã®ç¶æ ãšã€ãã³ãã®è¿œè·¡ãå¿ èŠãšãã
polyfills
ããå Žåã
defer fallfack
ã®å Žåãããã¯æ©èœããŸããã
äžèšã®åé¡ã®æ®éçãªè§£æ±ºçãšããŠãJSçšã®ã©ã€ãã©ãªã¢ãžã¥ãŒã«ãæŽçããããã®ããã€ãã®æšæºãéçºãããŸãããæãæåãªãã®ã¯ã AMD ïŒéåæã¢ãžã¥ãŒã«å®çŸ©ïŒã UMD ïŒãŠãããŒãµã«ã¢ãžã¥ãŒã«å®çŸ©ïŒãããã³CommonJSã§ãã å ±éã®å®£èšåœ¢åŒã®ã¢ãžã¥ãŒã«ã«åŸãèè ãšå ±éã®ãã¡ã€ã«ããŒããŒã®ååšã«ãããã»ãšãã©ã®åé¡ã¯è§£æ±ºãããŸããã
äžæ¹ãNode.JSãã©ãããã©ãŒã ã¯æŽ»çºã«éçºãããŠãããã¢ãžã¥ãŒã«ã®äŸåé¢ä¿ã¯å®å šã«ç°ãªãæ¹æ³ã§è§£æ±ºãããŸãã-åærequire-callã«ãã£ãŠãã¢ãžã¥ãŒã«ã¯å¯Ÿå¿ããç¹å®ã®åœ¢åŒãæã¡ãŸããã ãã®åŸãæè¡å§å¡äŒTC-39ã¯ãã¢ãžã¥ãŒã«ãã€ã³ããŒãããæ®éçãªæ段ã®éçºãéå§ããŸãããããã¯ãäžèšã®ãã¹ãŠã®åé¡ã解決ããåæã«ãµãŒããŒãšã¯ã©ã€ã¢ã³ãã§åãããã«åäœããã¢ãžã¥ãŒã«ããŒãã®åæããã³éåæã®ã»ãã³ãã£ã¯ã¹ãæäŸããããšã«ãªã£ãŠããŸãã ãã®ããŒã«ã¯ES6-ã¢ãžã¥ãŒã«ã«ãªããŸããã
ãã©ã³ã¹ãã€ã«ããã³ãã³ãã«ãã«ããŒã«ããES6ã¢ãžã¥ãŒã«ã®ãµããŒã
Ecmascript 262ããŒãžã§ã³6ä»æ§ãšãã®åŸã®ãšãã£ã·ã§ã³ã®åºçŸã«ãããå€ãã®æ°ããæ§ææ§é ãšãã€ãã£ãé¢æ°ãèšèªã«è¿œå ãããŸããã ååãšããŠããããã®ã»ãšãã©ã¯ãæ§ææ§ç¯ã®ããã®äºåçãªãã©ã³ã¹ãã€ã«ãããã³æ¬ èœããŠããæ©èœã®ããã®ããªãã£ã«ã®è¿œå ã«ãããå€ãããŒãžã§ã³ã®JSãšã³ãžã³ã§ç°¡åã«èµ·åã§ããŸãã
ES6-ã¢ãžã¥ãŒã«ã¯ãããŒãã®åæãã³ããããã³ã°ã»ãã³ãã£ã¯ã¹ããšã¯ã¹ããŒã/ã€ã³ããŒãããããšã³ãã£ãã£ã®ãã€ã³ãã£ã³ã°ãã€ã³ãã£ã³ã°ãã¢ãžã¥ã©ãŒã¹ã³ãŒããããã³éåžžã®ãã©ã³ã¹ãã€ã«ã§æäŸããã®ã容æã§ã¯ãªãä»ã®åŽé¢ãæäŸããŸããã
éçºè ã¯ãçŸåšã®Ecmascriptãã€ã¢ã¬ã¯ã6ã7ã8以éã§Webã¢ããªã±ãŒã·ã§ã³ãäœæããããšèããŠãããããæ¯èŒçå€ããã©ãŠã¶ãŒã§åäœããããã«ãtranspile-inaãå®è¡ããã¢ããªã±ãŒã·ã§ã³ã«é©åãª
polyfills
ãèªåçã«è¿œå ããå©äŸ¿æ§ãå¿ èŠã§ããåé¡ãããŸããã
ãããã®åé¡ã«å¯Ÿãã
transpilers
解決çã¯ããã©ã°ã€ã³
transpilers
ãš
polyfills
ã§ã«ã¹ã¿ãã€ãºå¯èœãª
bundle builder
polyfills
ã ã¢ã€ãã¢ã¯ãã¢ããªã±ãŒã·ã§ã³ã³ãŒããåç §ãã€ã¢ã¬ã¯ãã«å€æãããããšã§ããããã¯ãã¿ã¹ã¯ã«å¿ããŠãçŸåšã®ãã¹ãŠã®ãã©ãŠã¶ãŒïŒããšãã°ãES3ãŸãã¯ES5ïŒã§ãµããŒããããŠãããšèŠãªãããŸãã ãã®åŸããã¹ãŠã®ã©ã€ãã©ãªã¢ãžã¥ãŒã«ãšã¢ããªã±ãŒã·ã§ã³ã³ãŒããã¡ã€ã«ã¯ã1ã€ã®å€§ããªãã¡ã€ã«ããããããã³ãã«ã«çµåãããŸãã ãã®ãã¡ã€ã«ã¯ã¯ã©ã€ã¢ã³ãã«éä¿¡ãããåæãŸãã¯éåæã®ã€ã³ããŒãã¯å¿ èŠãããŸãããå¿ èŠãªã³ãŒãã¯ãã¹ãŠ
bundle
ãããã³ãŒãçªå·ã§ã¢ã¯ã»ã¹ã§ããããã§ãã
察å¿ããã¢ãããŒããå®è£ ããæåãªãœãªã¥ãŒã·ã§ã³ïŒ BrowserifyãšWebpack ãåŸè ã¯çŸåšã®äºå®äžã®æšæºã§ãã äºå®äžã®ãã©ã³ã¹ããŒã¿ãŒã¯ããã«ã§ãã ææ¡ãããã¹ããŒã ã«ã¯å€ãã®å©ç¹ããããŸãã
ãŸããã¹ããŒã ã«ãã©ã³ã¹ãã€ã©ãŒãååšããããããœãŒã¹ãããžã§ã¯ãã¯å®éã«ä»»æã®èšèªã§èšè¿°ã§ããŸãã éåžžãããã¯ææ°ããŒãžã§ã³ã®EcmaScriptãŸãã¯TypeScriptã§ãããæ§æãæ¡åŒµããå¯èœæ§ã¯ã»ãšãã©ç¡éã§ãã ESã®æåãªæ¡åŒµæ©èœã®1ã€ã¯ãReactã©ã€ãã©ãªãšãã®æŽŸçç©ã§äœ¿çšãããJSXã§ãã
第äºã«ããã©ã³ã¹ãã€ã«ãã§ãŒãºã§ã®ã³ãŒãå€æã®å¶åŸ¡ã«ããã ES6ãããã·ããªãã¬ã¯ã·ã§ã³æ å ±ãªã©ã®æ©èœã§ããã³ãŒãã®ãµããŒããå®è£ ããããšãå¯èœã§ã ã
ã³ãŒããã³ããªã³ã°ã䜿çšãããšã FïŒãOcamlãªã©ã§ã¯ã©ã€ã¢ã³ãã³ãŒããäœæã§ãããšããèå³æ·±ãçµæãåŸãããŸãã
æãããªå©ç¹ã«å ããŠããã³ãã«ããããœãªã¥ãŒã·ã§ã³ã«ã¯ããã€ãã®æãããªæ¬ ç¹ããããŸãã
ãŸããçµæã®
bundle
ãå§çž®ã®å¯èœæ§ãèæ ®ããŠããããªã¥ãŒã ãããªã倧ãããã¢ãã€ã«ãã©ãã£ãã¯ã§é¡èã«ãªããŸãã 第äºã«ã
bundle
ã¯ããŠãŒã¶ãŒãå¿ èŠãšããWebã¢ããªã±ãŒã·ã§ã³ã®èŠçŽ ã䜿çšããªãå Žåã§ãããŠãŒã¶ãŒã®ãã©ãŠã¶ãŒã§ããŒãããã³è§£éãããWebã¢ããªã±ãŒã·ã§ã³ã®ãã¹ãŠã®äŸåé¢ä¿ã絶察ã«å«ãŸããŸãã 第äžã«ã
bundle
å®å šã«é¢é£ããããå®å šãªæŽæ°ãå¿ èŠãªãããã©ã€ãã©ãªã®äŸåé¢ä¿ããã£ãã·ã¥ããå¯èœæ§ããªããªããŸãã
è² ã®å¹æã¯ãã¢ããªã±ãŒã·ã§ã³ã®éçºãšãããã°ã«çŸããŸãã ãã³ãã«ã¯ã»ãŒåžžã«
transpile
ã«é¢é£ä»ããããŠãããããç¹ã«å€§èŠæš¡ãªãããžã§ã¯ãã®å Žåãæ°ãã
bundle
ãååŸããããã»ã¹ã«ã¯æéããããå ŽåããããŸãã ããã¯ãéçºããã³ãããã°ããã»ã¹äžã«ã次ã®å€æŽãè¡ã£ãåŸã
bundle
ãåæ§ç¯ãããã®æ°ããããŒãžã§ã³ãã¯ã©ã€ã¢ã³ãã«ããŠã³ããŒãããå¿ èŠãããããšãæå³ããŸãã ããã«ããœãŒã¹ã³ãŒãã®ãã·ã³å€æã«ãããã»ãšãã©èªããªããªãããã©ãŠã¶ãŒã§ãããã¬ãŒã䜿çšããã®ãå°é£ã«ãªããŸãã
ãã¡ãããäžèšã®åé¡ã®ã»ãšãã©ã«ã¯ç¬èªã®è§£æ±ºçããããŸãã å®çšŒåã¢ãŒãã§ã¢ããªã±ãŒã·ã§ã³ã³ãŒãå šäœããã©ãŠã¶ã«ããŒãããªãããã«ãwebpackãã¯ãããžãŒã¯ã³ãŒããã£ã³ã¯åå²ã䜿çšããŸã ã ã€ã³ããŒãã®åçããŒãžã§ã³ã䜿çšããããšãã§ããŸããããã¯ãPromiseãè¿ããã¿ãŒã²ããã¢ãžã¥ãŒã«ã®éåæããŒããæäŸããŸãã
ãããã°çšã®ãœãªã¥ãŒã·ã§ã³ããããŸãã å ã®ãœãŒã¹ã³ãŒãã衚瀺ããããã«ãã©ãŠã¶ãŒãããã¬ãŒã§ããã²ãŒãããããšãããã¶ã€ã³ã¢ãŒãã®ã¿ãŒã²ãã
bundle
ã«å®è£ ããã
source maps
ã®ä»æ§ãéããŠå®çŸãããŸãã å®å šãªãªããŒã
bundle
ãªãã®éšåçãªã¢ããã°ã¬ãŒãã¯ãHot Module Reloadã䜿çšããŠè§£æ±ºãããŸãããçã®å¢åã¢ããã°ã¬ãŒãã¯åçŽãªå Žåã«ã®ã¿æ£ããæ©èœããŸãã
ES6ã¢ãžã¥ãŒã«ã®ãã€ãã£ããµããŒã
äŸåé¢ä¿ã®ãã³ãã«ã䜿çšããã¹ããŒã ã¯ããã®æ代ã«é¢é£ããŠããŸããããçŸåšããã¹ãŠã®ææ°ã®ãã©ãŠã¶ãŒã¯ES6ã¢ãžã¥ãŒã«ããã€ãã£ãã«ãµããŒãããŠããŸãã
ããã«ã¯ããã©ãŠã¶ãŒã®äžå®å šããšå¿ èŠãªæ©èœã®äžè¶³ã®ããã«
bundle
ãå¿ èŠã ã£ããããææ°ã®Webã¢ããªã±ãŒã·ã§ã³ã®ã¢ã»ã³ããªã«é¢ãããã¥ãŒã®æ¹èšãå¿ èŠã§ãã å€èŠ³åŸããã€ãã£ããã¶ã€ã³ã䜿çšãããšãã¯ããã«åªããçµæãåŸãããŸãã
第äžã«ãæ§ææ§é ã®é床ã®
transpile
ãšãã³ãŒãã®ãšãã¥ã¬ãŒãã«ãã眮æã¯ãæé©åã®
transpile
äœäžãšå°é£ã«ã€ãªãããŸãã ããã¯ãéåæããã³ãžã§ãã¬ãŒã¿ãŒé¢æ°ã«é©çšããã ãªãžã§ãã¬ãŒã¿ã©ã³ã¿ã€ã ã«çœ®ãæããããã¬ãã·ã«ã«å€æ°
let
/
const
æé©ã§ãªãvar-declarationã«å€æãããŸãã
ãã¡ãããããã¯ES6ã¢ãžã¥ãŒã«èªäœã«çŽæ¥é¢ä¿ãããã®ã§ã¯ãããŸããããéåžžã¯ã¢ã»ã³ããªãšã¢ããªã±ãŒã·ã§ã³ã¯ã©ã€ã¢ã³ããžã®é ä¿¡ã«ãã£ãŠæ±ºå®ãããŸãã ãã®æå³ã§ããããã¯çžäºæ¥ç¶ããããã®ã§ãã
第äºã«ãã¢ãžã¥ãŒã«ã¯ããã©ãŒãã³ã¹ã®ç¹ã§å¹ççã§ãã ES6ã¢ãžã¥ãŒã«ã¯ãããã©ã«ãã§é 延ã¢ãŒãã§ããŒãããã³å®è¡ãããŸãã ã€ãŸãã誀ã£ãŠããããã³ã°ã¢ãžã¥ãŒã«ãWebã¢ããªã±ãŒã·ã§ã³ã«è¿œå ããããšã¯äžå¯èœã§ãããããããã«äœ¿çšã§ããSPOFã®åé¡ã¯ãããŸããã
ES6ã¢ãžã¥ãŒã«ããµããŒãããŠããªãå€ããã©ãŠã¶ãŒã§æäœæ§ãç¶æããããã«ã
bundle
ããŠå€ããšãŒãžã§ã³ãã«æäŸããããšãã§ããŸãã åæã«ãES6ã¢ãžã¥ãŒã«ã®ã€ã³ããŒãã®èšèšæ©èœã«ããããã©ãŠã¶ãŒè¡ã®ãŠãŒã¶ãŒãšãŒãžã§ã³ããŸãã¯æ©èœæ€åºããŒã«ã«å¿ããŠãæäŸãããã³ãŒãã®åé¢ã§æ¡ä»¶ä»ãã§webpackãæ§æããå¿ èŠã¯ãããŸããã
åºå¥ããã«ã¯ã次ã®ã³ãŒãã§ååã§ãã
<html> <head> <script src="app/index.js" type="module"></script> <script src="dist/bundle.js" defer nomodule></script> </head> <!-- ⊠--> </html>
ES6ã¢ãžã¥ãŒã«ããµããŒãããªããã©ãŠã¶ãŒã¯ãåã«dist / bundle.jsãããŒãããå€ãã¹ããŒã ã«åŸã£ãŠåäœããŸãã ææ°ã®ãã©ãŠã¶ã¯app / index.jsããšã³ããªãã€ã³ããšããŠäœ¿çšããäŸåãªãœãŒã¹ãèªåçã«ããŒãããŸãã
äžèšã®ã¹ããŒã ãã¢ãžã¥ãŒã«ã®éåæããã³é 延ããŒããäŸåé¢ä¿ãã£ãã·ã¥ãã€ã³ã©ã€ã³ã¢ãžã¥ãŒã«ãããã³ãããã®CORSããªã·ãŒã®ããã«webpackãå¹ççã«æ§æããåé¡ã«ã€ããŠã¯ãã ES6ã¢ãžã¥ãŒã«ããã©ãŠã¶ãŒã®ã©ã³ãããµããŒãïŒãã³ãã«ãåèããæã§ããïŒã ãããã³ã ãã©ãŠã¶ã®ECMAScriptã¢ãžã¥ãŒã« ãã
ãŸãšã
EcmaScriptã¯é·ãéã®ããæ©ãã§ãããä»æ¥ãŸã§é²åãç¶ããŠããŸãã å€ãã®ãœãªã¥ãŒã·ã§ã³ã¯ãã®æ代ã«é¢é£ããŠãããã¯ã©ã€ã¢ã³ããšãŒãžã§ã³ãã«ãŸã çµã¿èŸŒãŸããŠããªãæ©èœã®ããã¢ã¯ãã£ããªãµããŒããªã©ãåé¡ã®è§£æ±ºãå¯èœã«ããŸããã çŸåšããã©ãŠã¶ãŒãšNode.jsãµãŒããŒã¯ããŒãžã§ã³æŽæ°ãé »ç¹ã«ãªãªãŒã¹ããææ°ã®EcmaScriptæ©èœãè¿œå ããŠããŸãã
ãã®çµæãéå»ã«äžè¬çãªããŒãžã§ã³ã®ãã©ãŠã¶ã®æ°æ©èœã®ãµããŒãããšãã¥ã¬ãŒãã§ãããœãªã¥ãŒã·ã§ã³ã¯ãæ§åŒã®ãšãŒãžã§ã³ãã«é©çšã§ããŸããã¿ã¹ã¯ã«ãã£ãŠã¯ãåå¥ã«ä¿å®ãããå®å šã«é€å€ããã®ãçã«ããªã£ãŠããŸãã
ã¢ãžã¥ãŒã«ã®äºåèªèšŒãšãªã³ã¯ãããã³ãã®åŸã®ãã³ãã«ã¯ãæè¿ãŸã§ã»ãšãã©ã®ãã©ãŠã¶ãŒã§ES6ã¢ãžã¥ãŒã«ããµããŒãããäž»ãªæ¹æ³ã§ããããçŸåšã§ã¯ãããã«æªåœ±é¿ãåãŒããæé©åããŒã«ãšãã£ãã·ã¥ããŒã«ã劚ããŠããŸãã
ãããã£ãŠãWebã¢ããªã±ãŒã·ã§ã³ã®ã¢ã»ã³ããªãèšå®ããéã«ã¯ãæ§æèŠçŽ ãã¢ãžã¥ãŒã«ã®ã€ã³ããŒã/ãšã¯ã¹ããŒããªã©ãææ°ã®ãšãŒãžã§ã³ãã«ææ°ã®EcmaScriptã³ãŒããæäŸããããšããå§ãããŸãã
ç·šéè ãã
ãããã¯ã«é¢ããNetologyã³ãŒã¹ïŒ
- è·æ¥ã ããã³ããšã³ãéçºè
ãã
- è·æ¥ã ãŠã§ãéçºè
ãã
- JavaScriptããŒã·ãã¯ã³ãŒã¹ãªã³ã©ã€ã³ããã°ã©ã ã
- ãªã³ã©ã€ã³ããã°ã©ã ã NodeãAngularJSãMongoDBïŒæ¬æ ŒçãªWebã¢ããªã±ãŒã·ã§ã³ã®éçº ã;
- ãªã³ã©ã€ã³ããã°ã©ã ã ãã©ãŠã¶ã®JavaScriptïŒã€ã³ã¿ã©ã¯ãã£ããªWebããŒãžã®äœæ ã