
ãã©ãã¯ããã¯ã¹åããJavaScriptã³ã¼ããå¯è¦å
ãç¹å®ã®äººããä¿®æ£ã§ããªãJavaScriptã³ã¼ãã¯ãã¾ãã«ãã©ãã¯ããã¯ã¹ã§ãããæè¡çè² åµã¨ããããé·ãç®ã§è¦ãã°ãæ©è½è¿½å ãå質æ¹åã«å¤§ããªæ¯éã¨ãªããã¨ã¯æããã§ã誰ãã解決ãããã¨èããã¯ãã ãããããå¤ãã®ä¼æ¥ã§ã¯ãµã¼ãã¹ã®æ¹åãæ©è½è¿½å ãåªå ãããæè¡çè² åµã®ååã»æ¹åã¯å¾åãã«ãããã¡ã ããããè² åµãè¿ãä½æ¥ãããæ°è¦éçºã®è¶³ããã¨èãããã¦ãããã¨ããããã
ãæ¬ã»ãã·ã§ã³ã«ç»å£ããé´æ¨æ½¤æ°ãããããã課é¡ãæãã¦ãããé´æ¨æ°ã¯ã転è·ãµã¤ããDODAããæ±äººæ å ±ãµã¼ãã¹ãanããæããããã¼ã½ã«ãã£ãªã¢æ ªå¼ä¼ç¤¾ï¼æ§ç¤¾åï¼æ ªå¼ä¼ç¤¾ã¤ã³ããªã¸ã§ã³ã¹ï¼ã§ããªãã¡ã©ã«æ¡ç¨æ´»æ§åãµã¼ãã¹ãMyReferãã¨ãã£ãæ°è¦ãµã¼ãã¹ã®éçºãæ å½ãè¿ éãªæ°è¦æ©è½ã®è¿½å ãæ¥åææã¨ãã¦ããã

ããæè¡çè² åµã®åé¡ã¯æãããªãããMyReferã¯ãµã¼ãã¹ã¨ãã¦ã¾ã ã¾ã æé·æ®µéã«ããã顧客ä¼æ¥ã®æ¥åãåæ»ã«é²ããããã«ããæ¥ãããã§æ°è¦æ©è½ãéçºãããã¨ãå¿ é ããæ°è¦æ©è½éçºãæ¢ããã«ã並è¡ãã¦æè¡çè² åµãè¿ãåãçµã¿ãèããå¿ è¦ããã£ããããã§ã課é¡ã®æ確åããã©ã解決ãããããæ¹åã®æ¹éãã®3ã¹ãããã§ã¢ããã¼ããããã¨é´æ¨æ°ã¯èªãã
ãé´æ¨æ°ä»¥å¤ã®éçºã¡ã³ãã¼ãããªãã¨ãªãéçºãã¥ãããã¨æ¼ ç¶ã¨æããªããããã®åå ãããããªãã¹ãã¬ã¹ãæ±ãã¦ãããããã§ãã¡ã³ãã¼å ¨å¡ãéã¾ããã©ã®ãããªåé¡ãçãã¦ãããããä»ç®ã§æ¸ãåºãã¯ã¼ã¯ã·ã§ãããéå¬ããã¾ãã¾ãªå£°ãä¸ããä¸ã§ãJavaScriptã«é¢ãããã®ãã¾ã¨ãã¦ãã£ãçµæã大ãã以ä¸2ã¤ã®åé¡ã«éç´ããã¦ãã£ãã¨ããã
- è¤æ°ã®ãã¡ã¤ã«ãã¾ããã£ã¦ãããã¨ã«ããè¤éã
- DOMã¨ã¤ãã³ããªã¹ããé¢ãããã¦ãã
äºå¤§èª²é¡ãwebpackã¨Reactã®æ´»ç¨ã«ãã£ã¦è§£æ±º
ãåé¡1ãè¤æ°ã®ãã¡ã¤ã«ãã¾ããã£ã¦ãããã¨ã«ããè¤éã
ããã®åé¡ã«ã¤ãã¦ãé´æ¨æ°ã¯é¢æ°å¦çæã®æéãæãããä¾ãã°ãã²ã¨ã¤ã®å¦çãè¤æ°ã®ãã¡ã¤ã«ã«ã¾ããã£ã¦æ¸ããã¦ããããã®ã©ããã§å®ç¾©ããã¦ãããHoge.fugaé¢æ°ããä¿®æ£ããªãã¦ã¯ãªããªãå ´åã大éã®ã¿ã°ã®ä¸ããå®ç¾©é¨åãæ¢ãåºããªããã°ãªããªãã

ããã®åé¡ã解決ããã«ã¯ãè¤éãªæ¤ç´¢ãè¡ããªãã¨ãã大éã®Scriptã¿ã°ã®ä¸ã§ãã©ãã§å®ç¾©ãã¦ããã®ããããããå¿ è¦ããããå ·ä½çã«ã¯ECMAScript 2015ã®importæ§æã§æ¸ãã¨ã1ï½2ãã¡ã¤ã«ã«çµãè¾¼ããããããå¯è½ã«ãããããwebpackããå°å ¥ããä¾åé¢ä¿ã解決ã§ããããã«ãããwebpackã¨ã¯ãJavaScriptãã¡ã¤ã«ã®åé ã«è¨è¼ããã¦ããimportããã©ããè¤æ°è¡ã®ã³ã¼ããã²ã¨ã¤ã®ãã¡ã¤ã«ã«ãã¦åºåã§ãããã¼ã«ã ã

ãwebpackãå¿ è¦ã ã£ãçç±ã«ããµãã¼ããã©ã¦ã¶ã®åé¡ããã£ããMyReferã§ã¯ãµãã¼ããã©ã¦ã¶ã¨ãã¦ECMAScript 2015ã®importæ§æã«å¯¾å¿ãã¦ããªãIE11ãå«ãã¦ãããimportæ§æã使ç¨ããã³ã¼ããIE11ä¸ã§å®è¡ãã¦ãåä½ããªãããã®ãããwebpackã使ç¨ãã¦importæ§æã使ç¨ãã¦ããJavaScriptã®ä¾åé¢ä¿ã解決ããåºåããããã¡ã¤ã«ãHTMLããèªã¿è¾¼ãæ¹æ³ãã¨ã£ãã
ãåé¡2ãDOMã¨ã¤ãã³ããªã¹ããé¢ãããã¦ãã
ãããã¦ããã²ã¨ã¤ããDOMã¨ã¤ãã³ããªã¹ããé¢ãããã¦ãããåé¡ãä¾ãã°ãããããHTMLã¨jQueryã®ã½ã¼ã¹ã³ã¼ãã§ããã»ã¬ã¯ã¿ãjs-hoge-buttonããå¤æ°ã«æ ¼ç´ããã¦ãããã¨ããåçã«åºåããã¦ãããã¨ããããããã§ã¯ã³ã¼ãã¨ãã¦ãããã«ããã

ãããããHTMLã¨jQueryã®ã¯ãªãã¯æã®å¦çããã²ã¨ã¤ã®ãã¡ã¤ã«ã«ã¾ã¨ãã¦æ¸ããã¦ããã°ãã®åé¡ã¯è§£æ±ºã§ãããããã§ãMyReferã§ã¯Reactãå°å ¥ããã¿ã³è¦ç´ ã¨ã¯ãªãã¯æã®é¢æ°ãã²ã¨ã¤ã®ãã¡ã¤ã«ã«è¨è¼ãããã¨ã«ãã£ã¦è§£æ±ºã試ã¿ãã

ãããã«Chromeã®React Developer Toolsã§ããã°ãããªã¼ç¶ã«ã³ã³ãã¼ãã³ãåã確èªã§ãããã¯ã©ã¹åããããããããã¿ã³ãæ¼ããéã®æåãããããªããåé¡ã解決ã§ããã¨ããã
ããããªãã¨ãjQueryã¯å®å ¨ã«ãã使ããªãã®ããã¨ããçåãçããããé´æ¨æ°ã¯ãjQueryã§æ¸ããã¦ããã½ã¼ã¹ã³ã¼ãã¯å®¹æã«æ¨ã¦ãããªããMyReferã§ã¯Reactã©ã¤ããµã¤ã¯ã«ã¡ã½ããã®ä¸ã«éãè¾¼ããå½¢ã§å©ç¨ãã¦ãããã¨èª¬æããã
ESLintã®å°å ¥
ãããã«é´æ¨æ°ã¯ãJavaScriptç¨éçæ¤è¨¼ãã¼ã«ãESLintãã«ã¤ãã¦ãè¨åãå½æã®MyReferã®ã³ã¼ãã§ã¯ã°ãã¼ãã«ã«åå¨ããåå空éãããããããå½äºè 以å¤èª°ãç¥ããªãã¨ãã£ãç¶æ³ãçºçãã¦ãããããã ãã§ãªããvarããletããconstããªã©ãã¤ãå¿ãããã¨ã§ãæå³ããã°ãã¼ãã«å¤æ°åãã¦ãã¾ããã¨ããã£ãã
ããã®åé¡ã解決ããããã«å°å ¥ããã®ãESLintã ãç¹å¥ãªçç±ããªãéãã°ãã¼ãã«ãªé åã«å¤æ°ãå¢ãããªãããã«ããevalãç¦æ¢ãã¾ããå®è¡æã¨ã©ã¼ãå¼ãèµ·ãããããªãã»ãã³ãã³å¿ããªã©ãå«ãã¦ãã§ãã¯ãã¦ããã