ïŒtranslãããïŒ ãã©ãŠã¶ãŒïŒSourceMapïŒã§ã³ã³ãã€ã«ãããã³ãŒããæäœããæè¡ã«ã€ããŠã¯ãçŽ1幎åã«è©³çŽ°ãªèšäºïŒ 翻蚳 ïŒãæ¢ã«ãããŸããã çŸåšããã®æè¡ã¯å€ªéœã®äžã§ç©æ¥µçã«ãã®äœçœ®ãç²åŸããŠããŸãã ããšãã°ããããã³ã°ã®ã³ã³ãã€ã«ã«ã€ããŠã®ã¿è©±ããããŸããããããŒãžã§ã³1.6.1以éãCoffeescriptã³ã³ãã€ã©ãŒã¯ããããã¡ã€ã«ã®äœæã®ãµããŒããåãåããŸããã Jetbrains Webstorm 6.0 / PhpstormïŒ2013幎3æïŒã§ã¯ãã³ãŒããæäœããããã®SourceMapãµããŒããå°å ¥ãããŸãã ã Typescriptã¯ããŒãžã§ã³0.8.1ïŒ2012幎11æïŒä»¥éãµããŒãããŠããŸãã ããã³ããšã³ãã®ãã¢ã»ã³ãã©ãã䜿çšããæåäœæ¥ã®æéãçµéããããšã¯èª°ããç解ããŠããŸãã誰ããã³ãŒããã足ã䌞ã³ãå Žæãç¥ãå¿ èŠããããŸãã çž®å°ããããã¡ã€ã«ã³ãŒããã³ãŒãã®æåã®ã¢ããªã±ãŒã·ã§ã³ã«ã€ããŠã話ããŠããŸãããUglifyJSãClosure CompilerãGWTïŒå°ãªããšãïŒã§ã¯ãµããŒããããŠããŸãã JSãšCSSã³ãŒãã³ã³ãã€ã©ã«ã€ããŠã§ãã
ãããŠæè¿ïŒ2013幎1æïŒããã®å€§èŠæš¡ãªæè²èšäºãç»å Žããã³ãŒãã«ãŒããã¯ãããžãŒã®ä»çµã¿ãäŸãšãšãã«èª¬æããŸããã æåã®èšäºã詳ãã説æããŸãããã2çªç®ã®èšäºã翻蚳ããŠã害ã¯ãããŸãããä»ã®èšèãã€ã©ã¹ãã§åãããšã説æããå®è·µã«é²ã¿ãŸãã
ãããå€ãéåžžã®ç¥èããçµéšã«æž¡ãããšã¯ãåžžã«äžå®ã®éå£ãæ§æããŸãã ãã¬ãŒãã³ã°ãã¡ã€ã«ã䜿çšããŠã³ãŒãã«ãŒããã¡ã€ã«ãäœæããçµæã確èªããŸãããã®éãã³ã³ãã¥ãŒã¿ãŒäžã§ç¬èªã®ãããžã§ã¯ããçµã¿ç«ãŠãããã®äœæ¥ç°å¢ãååŸããŸãããããŸã§ç¥ã£ãŠããã䜿çšããã®ãæãã£ããã¹ãŠã®ã³ã³ãã€ã©ãŒãšãããã¡ã€ã¢ãŒã¯ãçµã¿ç«ãŠãå¿ èŠããããŸããæè¿ã®ããã³ããšã³ãèšèªãŸã§ã®ãšããŸããã¯ãªã³ãŒãã®1ã€ã
Grunt 0.4+ã³ã¬ã¯ã¿ãŒã®æ°ããããŒãžã§ã³ã䜿çšããå Žåãèšäºã«èšèŒãããŠããèšå®ãšã¯è¥å¹²ç°ãªãèšå®ãå¿ èŠã«ãªãããšã«æ³šæããŠãã ããã habrahabr.ru/post/170937ã§0.3.9ãã0.4xãžã®ç§»è¡ã®è©³çŽ°ããèªã¿ãã ããã
èè ã¯ãã¹ã®ã¹ã¯ãªãŒã³ã·ã§ããã䜿çšããŸããã Chromeã®å Žåããã©ãŠã¶ã®èšå®ã¯WindowsããŒãžã§ã³ãšã¯éåžžã«ç°ãªããããäžéšã®å Žæã§ã¯Windowsã®Chromeã®ãã·ã¢èªããŒãžã§ã³ã®ã¹ã¯ãªãŒã³ã·ã§ãããè¿œå ãããŠããŸãã
ã¯ãã¹ãã©ãŠã¶éçºã®å Žåãã¡ã€ã³ã·ã¹ãã ã®ããããã§äœæ¥ã§ããããšãæãŸããã§ãã Linuxããã³MacOSã§è³ªåããªãå Žåã¯ããã¹ãŠã®äŸãWindowsã§æ£åžžã«æ©èœããããšã確èªããããšãéèŠã§ãã 翻蚳ã®éçšã§ãWindows XPç°å¢ãšææ°ã®ïŒ2013幎4æçŸåšïŒããŒãžã§ã³ã®ããã°ã©ã ã§ãµã³ãã«ããã§ãã¯ããã確å®ãããŸããã ãã®çµæã5ã€ã®äŸã®ãã¡2ã€ã§æ¹åãè¡ããã翻蚳èšäºã«ã³ã¡ã³ããè¿œå ãšããŠã¬ã€ã¢ãŠããããŸããã ïŒæ¹åã«é¢ããã¡ãã»ãŒãžãèšäºã®äœè ã«éãããŸãããïŒãããã¯ãæ°ããããŒãžã§ã³ïŒç¹ã«Grunt 0.4ãšCoffeescript 1.6.1ïŒã®ãµããŒãã®äž¡æ¹ã®ç¹ã§ãWindowsã§ã®ãã¹ãŠã®æ©èœã®ããã©ãŒãã³ã¹ã«å¯Ÿããä¿¡é Œãšåæ§ã«ãäŸãçŸå®ã«è¿ã¥ããã®ã«åœ¹ç«ã¡ãŸãã
次ã®æ©èœã¯ãèè ã®githubã®ã¢ãŒã«ã€ãã§ãã 260æåãè¶ ãããã¹ããããããWinRarã§ã¯å®å šã«ã¯å±éãããŸããïŒãã ããããã¯ãçããã¹ãæã¡ããã¹ãŠã®ãµã³ãã«ãå®è¡ãããµã³ãã«ã®éå§ãã¡ã€ã«ã®äœ¿çšã劚ããŸããïŒã ãã¹ãŠã®ãµã³ãã«ã®å®è¡åŸã«ã€ã³ã¹ããŒã«ããããã¡ã€ã«ãå«ãã¢ãŒã«ã€ãå šäœãïŒå¥œå¥å¿ããïŒè¡šç€ºããã³è§£åããã«ã¯ã 7zipãŸãã¯WinRar以å€ã®å¥ã®ã¢ãŒã«ã€ãã䜿çšããå¿ èŠããããŸãã
å€ãã®ã³ã¡ã³ããã³ã¡ã³ããããã³å€æŽããããŸãïŒä»¥éãåºå¥ã®äŸ¿å®äžããåŒçšã圢åŒã§åºå¥ããŸããïŒããã§ããããã¯æ°ããèšäºã§ã¯ãªããã³ã¡ã³ãã§ãããŒã«ã«ããã³ããªã«æåã®ç¹åŸŽãèæ ®ãã翻蚳ã§ãã ãªããªããæ°ãããã¯ãããžãŒã®æ®åã«é¢é£ããŠãå€ãã®ä»äºã®åªããåžå°ãªçµç¹ã«æ¬æãè¡šããªããã°ãªããªãããã§ãã
ãããããã®ãããã¯ã«é¢ããäž¡æ¹ã®èšäºïŒ1幎åã«ç¿»èš³ãããæ€èšãããŠããïŒã¯æ代é ãã§ããããïŒå€ãã®èšè¿°ã¯çŸåšã®ç¬éã«å¯Ÿå¿ããŠããŸããïŒããã®è³ªåã¯ããã°ãã¹ãŠã®åé¡ãã«ããŒããŠããããããã®èšäºã¯ãããã³ã°ãšä»æ¥ã®ããŒã«ãšãã©ãŠã¶ã®ç¶æ ã
ãœãŒã¹ããããšã¯äœã§ããïŒ
ã³ãŒãã«ãŒãã¯ãäœæ¥äžã®ã³ãŒããšéçºäžã«äœæãããœãŒã¹ã³ãŒãïŒãœãŒã¹ïŒãšã®å¯Ÿå¿ã瀺ããèšèªã«äŸåããªãæ¹æ³ãæäŸããŸãã ãããžã§ã¯ãããã«ãããåŸãæºåãããã³ãŒãã®é åå šäœãèŠããšãæçµçãªã³ãŒãã®ã»ã¯ã·ã§ã³ãšãã®ãœãŒã¹è¡ã®å¯Ÿå¿ãèŠã€ããããšãéåžžã«é£ãããªããŸãã ã³ãŒãã«ãŒãã«ã¯ãããã®éä¿¡ãä¿åããããããããšãã°ãšã©ãŒã®å Žæãå°ãããšããœãŒã¹ãã¡ã€ã«å ã®æ£ç¢ºãªå Žæã衚瀺ãããŸãã ã³ãŒããèªã¿ããããªãããããã°ãããããšããããããããã¯éçºè ã«ãšã£ãŠéåžžã«æçã§ãïŒ
ãã®ãã¥ãŒããªã¢ã«ã§ã¯ãéåžžã«åçŽãªJS + SASSã³ãŒããã³ã³ãã€ã«ããã³ãŒãã«ãŒãã䜿çšããŠãã©ãŠã¶ãŒã§ãœãŒã¹ãã¡ã€ã«ã調ã¹ãŸãã ãã¢ãã¡ã€ã«ãããŠã³ããŒãããŠå§ããŸãããïŒ
Gruntã®ææ°ããŒãžã§ã³ïŒ0.4ïŒã¯ãµã³ãã«ã§åäœãããããäœæè ã®ãµã³ãã«ã§ã¯ãªãã æŽæ°ããã翻蚳 è ã®ãµã³ãã«ãããŠã³ããŒãããããšããå§ãããŸãã ãããã«ã¯ãèµ·åãã¡ã€ã«ãšã€ã³ã¹ããŒã«ããã³äŸã®çµæã®äž¡æ¹ãå«ãŸããŠãããããã¢ã¯ã·ã§ã³ã®æ£ç¢ºæ§ãšæåã確èªã§ããŸãã ã
ãã©ãŠã¶
ãã®èšäºã®å·çæç¹ã§ã¯ãChromeããŒãžã§ã³23ã¯JSããã³SASS SourceMapsããµããŒãããŠããŸãã ãã®ãããã¯ã¯éçºã®æŽ»çºãªæ®µéã«ãããããFirefoxãè¿ãå°æ¥ãµããŒããåããŸãã ãããã®èŠåã䜿çšããŠããã©ãŠã¶ãŒã§ã³ãŒãã«ãŒãã䜿çšããæ¹æ³ãèŠãŠã¿ãŸãããã
ïŒçŽtranslã:)ãã®èšäºã®æåŸã«ã¯ãFirefox + Firebugã§ã®SASSã®SourceMapãµããŒãã®äŸããããŸãã Firefoxã®æ°æ©èœïŒ Firefox DevToolsã®å°æ¥ ïŒ2013幎3æ17æ¥ïŒ ãŸãã¯ç¿»èš³ç ïŒ
ãCoffeeScriptã®ãµããŒãã ãããå®è£ ããããã«ãSourceMapããµããŒãããŸããã ããã¯ã»ãã£ãããžã§ã©ã«ããSourceMapãšCoffeeScriptããµããŒããããããã¬ãŒããŒãžã§ã³ããã¢ã³ã¹ãã¬ãŒã·ã§ã³ããŸã
ããã¯ã®ä»äºã¯ãCSSãã¡ã€ã«ãšJSãã¡ã€ã«ã®çž®å°åã®ãµããŒãã«ã圹ç«ã¡ãŸããã
*ïŒ wiki.mozilla.org/DevTools/Features/SourceMap
Chromeã®ãœãŒã¹ããã
ãŸããèšå®ã§ãããã³ã°ãµããŒããæå¹ã«ããå¿ èŠããããŸãã
1ïŒChromeéçºè ããŒã«ãŠã£ã³ããŠãéããŸãã衚瀺->éçºè ->éçºè ããŒã«ïŒF12ïŒ;
2ïŒå³äžé ã®ãèšå®ããã¯ãªãã¯ããŸãã
3ïŒãäžè¬ããšããœãŒã¹ããããæå¹ã«ããããéžæããŸãã
Windowsã®å ŽåïŒtranslãããïŒ ïŒ
1ïŒæ§æãšç®¡çïŒå³äžé ïŒïŒF12ïŒ;
2ïŒéçºè ã®ãŠã£ã³ããŠ-å³äžé ã®ãèšå®ãã
3ïŒããœãŒã¹ããããã¯ã§ãäžè¬ããšããœãŒã¹ããããæå¹ã«ããããéžæããŸãã
èšçœ®
ãã¢ã¢ãŒã«ã€ã ïŒç¿»èš³æã«æ€èšŒããã翻蚳è ã®ãµã³ãã«ãžã®ãªã³ã¯ïŒãããŠã³ããŒãã ããéå§ããã£ã¬ã¯ããªãéããŸãã ãã¡ã€ã«ãšãã£ã¬ã¯ããªæ§é ã¯éåžžã«åçŽã§ããscripts/ script.jså ã®ç°¡åãªJavaScriptã§ãã index.htmlãéããåŸãã¹ã¯ãªããã¯ãŠãŒã¶ãŒãã«ã©ãŒã³ãŒããå ¥åããŠããŒãžã®èæ¯è²ãå€æŽããŸãã
/start âââ index.html âââ /scripts â âââ jquery.d.ts â âââ script.coffee.coffee â âââ script.js â âââ script.typescript.ts âââ /styles âââ style.css âââ style.sass
JavaScriptãTypeScriptãCoffeeScriptãã¡ã€ã«ã®ç°¡åãªã¹ã¯ãªãããèŠãŠãã ããã
ããŸããŸãªã³ã³ãã€ã©ã䜿çšããŠãã¢ã»ã³ããªãäœæãã察å¿ããã³ãŒãã«ãŒããã¡ã€ã«ãçæããŸãã
5ã€ã®ç°ãªãæ¹æ³ã䜿çšããŠãã³ã³ãã€ã«ããæå°åãããã¹ã¯ãªãããšé¢é£ããããããçæããŸãã ãã¹ãŠã®ãªãã·ã§ã³ã䜿çšããããæ¢ç¥ã®ã³ã³ãã€ã©ãŒã®ã¿ã䜿çšã§ããŸãã
ãªãã·ã§ã³ïŒ
1. ã¯ããŒãžã£ãŒã³ã³ãã€ã© ã
2. GruntJSãšJSMin ã
3. Uglifyjs 2 ã
4. CoffeeScript Redux ã
5. TypeScript ã
çŸåšã®ããŒãžã§ã³ã®ããã°ã©ã ã«åãããŠãµã³ãã«ããã¹ãããã³æ¹è¯ããåŸããµã³ãã«çŸ€ã«ã¯2ã€ã®ãªãã·ã§ã³ãè¿œå ãããŸããã
2. a JSMinã䜿çšããGruntJSïŒ0.4.xïŒ ã
4.a CoffeeScript-Reduxã§ã¯ãªããå ã®ããŒãžã§ã³1.6.2 ã
æåã®ããŒãžã§ã³ã§ã¯ãæ°ããããŒãžã§ã³ã®ã€ã³ã¹ããŒã«ã«ã€ããŠè©³ãã説æããŸããããã¯ã2013幎2æãŸã§ã®ææ°ããŒãžã§ã³ã§ãã0.3.xãšã¯å€§ããç°ãªããŸãã 2çªç®-2013幎2æã«Coffeescriptã®ããŒãžã§ã³1.6.1ããç»å Žãããããã³ã°ã®èµ·åãšãã¹ããïŒ2012幎9æ以éããã®åœ¹å²ã¯ã¯ããŒã³-Coffeescript Reduxã«ãã£ãŠæããããŸãããïŒ
ïŒtranslãããïŒã³ãŒããšææ¡ããããªãã·ã§ã³ã®åãæ¿ãæ¹æ³ãåããŠç¥ã£ãã®ã¯æ¥ããããã§ãã ããããèè ã«ãã£ãŠå€ãã®äœæ¥ãè¡ãããé©ãã¹ãæè¡ãæäŸãããŠããŸãã ãã®èšäºã¯ããŸãèšèšãããŠããŸãã ãããããŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ã¯çªç¶äžäœã§ãã ã³ã¡ã³ãã®èšé²ãšåé€ãä»ããŠãªãã·ã§ã³ãåãæ¿ããæ¹æ³ã¯ãèªåã¢ã»ã³ããªã¢ãããŒãã®ã€ããªãã®ãŒãšççŸããŸãããã¹ãŠãå¯èœãªéã管çããããããå¿ èŠããããŸãã 衚瀺ãªãã·ã§ã³-ãã ããŒãžURLãä»ãããªãã·ã§ã³ã®åãæ¿ãã劚ãããã®ã¯ãããŸããã ã¢ã³ã«ãŒã®ãªãã·ã§ã³ãã©ã¡ãŒã¿ãŒã«å¿ããŠãããŒãžã®èªã¿èŸŒã¿äžã«1ã€ãŸãã¯å¥ã®ã¹ã¯ãªãããèªã¿èŸŒãã¹ã€ãããäœæããŸãã ããã¯åçãª1ããŒãžã®ããŒãã§ã¯ãããŸããããããã»ã©é ãã¯ãããŸããããã³ãŒããåãæ¿ããããããã§ã«åªããŠããŸãã
var lHash = location.hash.substr(1).split('='); if(lHash && lHash.length ==2 && lHash[0] =='option') var optionName = lHash[1]; if(optionName && !parseInt(optionName)) optionName = {closure:1,jsmin:2,uglifyjs:3,coffeescript:4,typescript:5}[optionName.toLowerCase()]; console.log(optionName); optionName = optionName ||0; var loadScript; (loadScript = function(i){ var scr = document.createElement('SCRIPT'); scr.setAttribute('type', 'application/javascript'); scr.src ='scripts/script.' + ('|closure|jsmin-grunt|uglify|coffee.min|typescript.min'.split('|')[i]) +(i?'.':'') +'js'; document.getElementsByTagName('head')[0].appendChild(scr); })(optionName);
ããã§ãã³ãŒãå ã®å€§éã®ã³ã¡ã³ããåãé€ãããããããã©ããŒããŠåãæ¿ããå¿ èŠããããŸããã ã¢ã³ã«ãŒã®è¿œå ïŒoption = <number>ãŸãã¯ïŒoption = <example_name>ãŸãã¯æ¬ èœïŒãŸãã¯ãã©ãŒããããšã©ãŒïŒã¢ã³ã«ãŒã¯ãscr.srcã«ãªã¹ããããŠãããªãã·ã§ã³ããç®çã®ã¹ã¯ãªãããå®è¡ããããã«åŒã³åºããŸãã å°æ¥çã«ã¯ãç¬èªã®ãªãã·ã§ã³ãç¬èªã®ååã§è¿œå ã§ããŸãã
ãŸããããã¯ã°ã©ãŠã³ãã¹ã€ããã¯ãªããšãªã䜿ãã«ãã-ã³ãŒãã®åã«ã·ã£ãŒããå¿ èŠãšããŸãã è²ãèšèã®åœ¢ã§äœ¿ããããšããé¡æã¯ç解ã§ããŸãããè²ãæ±ãããšã«æ £ããŠãã人ã¯ã»ãšãã©ããŸããã ã¿ããã¢ããïŒ
var colr = $("#color").val().toUpperCase() , cL = colr.length; for(var i in cL) if(cL[i] <'0'|| cL[i] >'9'&& cL[i] <'A'|| cL[i] >'F') // hex- break; document.body.style.backgroundColor = (colr.charAt[0] !='#' && i < cL ?'':'#') + colr;
ãããããäžèŠãããšé£ããããã«èŠããŸãããåå§æ§ã«èµ·å ããæåŠã¯çºçããŸããã ãã以å€ã®å Žåãææ°ã®ãã«ããã¯ãããžã䜿çšããŠãããããã³ãŒãã§ã¯ããããããã€ã³ã¿ãŒãã§ã€ã¹ãè¡šçŸã§ããŸããã åŸã§ãããé«åºŠãªã³ãŒãã§åžæã圢åŒåããããã»ã©åå§çã§ã¯ãªãloadScriptãšã³ãŒãã®ã¢ã³ã«ãŒãªãŒããŒãèãåºããããããã¹ãŠãã³ãŒããŒã¹ã¯ãªããã«èšè¿°ãããã«ãã©ã€ãã©ãªã«ä¿åããŸãã çµå±ã®ãšãããç§ãã¡ã¯ãåå§æ§ã®åŠ¥åã«å察ããåçŽã«æœè±¡åã®è€éãªè«çã衚瀺ããããšããé¡æããããããžã§ã¯ãã®çµã¿ç«ãŠã«æ¥ãŸãã
ãªãã·ã§ã³1ïŒã¯ããŒãžã£ãŒã³ã³ãã€ã©
Google Closure Compilerã¯JavaScriptæé©åããŒã«ã§ãã ã³ãŒããåæããäžèŠãªéšåãåé€ããæ®ããçž®å°ããŸãã ããã«ããœãŒã¹ããããçæã§ããŸãã
次ã®æé ãå®è¡ããŠãã¹ã¯ãªããã®æé©åããŒãžã§ã³ãäœæããŸãã
- ææ°ã®Closure CompilerãããŠã³ããŒãããŠãã ããã
-
compiler.jar
ãã¡ã€ã«ãã¹ã¯ãªãããšãšãã«ãã£ã¬ã¯ããªã«é 眮ããŸãã - ã³ãã³ãããã³ããã§ãã
scripts/
ããã£ã¬ã¯ããªã«ç§»åããã³ãã³ããå®è¡ããŠãæé©åãããscript.closure.js
ã§å®è¡å¯èœãªscript.closure.js
ãã¡ã€ã«ãäœæããŸãã
java -jar compiler.jar --js script.js --js_output_file script.closure.js
- ããªãã·ã§ã³Aãã®ã³ã¡ã³ããå€ããŠã
index.html
ãäœæããããã¡ã€ã«ã«é¢é£ä»ããããŠããããšã確èªããŸãã
ãã©ãŠã¶ã§
index.html
ãéããéçºè ããŒã«ã®[ãœãŒã¹]ããã«ãèŠããšãã¹ã¯ãªãã
script.closure.js
æé©åãããããŒãžã§ã³ãžã®ãªã³ã¯ãããããŸã
script.closure.js
ã å¿ èŠãªã€ã³ãã³ãã䜿çšããŠå ã®ã³ãŒããã¡ã€ã«ãšéä¿¡ããæ¹æ³ã¯ãããŸããã ã¹ã¯ãªãããã£ã¬ã¯ããªã§æ¬¡ã®ã³ãã³ããå®è¡ããŠãã³ãŒãã«ãŒããã¡ã€ã«ãäœæããŸãã
java -jar compiler.jar --js script.js --create_source_map script.closure.js.map --source_map_format=V3 --js_output_file script.closure.js
Closure Compilerã¯2ã€ã®ãªãã·ã§ã³
--create_source_map
ãš
--source_map_format
ã䜿çšããŠããœãŒã¹ãããããŒãžã§ã³3ã§
script.closure.js.map
ããã
script.closure.js.map
ãäœæããããšã«æ³šæããŠãã ãããããããããã ãã§ã¯ãããŸããã å¹æã確èªããã«ã¯ãã³ã³ãã€ã«ããã
script.closure.js
ãã¡ã€ã«ã®æåŸã«ãœãŒã¹URLãè¿œå ããŠããã®å Žæã«é¢ããããŒã¿ãå«ãŸããããã«ããŸãã
//@ sourceMappingURL=script.closure.js.map
éçºè ããã«ãä»ããŠãã©ãŠã¶ã§ã¹ã¯ãªããã衚瀺ãããšãå ã®ãã¡ã€ã«ãšæé©åããã
script.closure.js
äž¡æ¹ã®ãã¡ã€ã«ã衚瀺ãã
script.closure.js
ã ãã©ãŠã¶ã¯æé©åããããã¡ã€ã«ã䜿çšããŸããããœãŒã¹ãããã䜿çšãããšããœãŒã¹ãã¡ã€ã«ã«ãªã³ã¯ã§ããŸãã
ãã¬ãŒã¯ãã€ã³ãã§ãããã°ããŠã¿ãŠãã ããã ãœãŒã¹ã衚瀺ãããšãã芳å¯ãããåŒãšå€æ°ã¯ãŸã å©çšã§ããŸããã å°æ¥ãããã衚瀺ãããããšãæåŸ ããŸãããïŒ
ããªã«æåã䜿çšãããŠãŒã¶ãŒã«ã¯ããã1ã€ãã€ãŸã2ã€ãã€ãŸã1ã€ã¯ãã©ãŠã¶ãŒã«ããã1ã€ã¯ã³ã³ãã€ã©ãŒã«ååšããããšã«æ°ä»ã幞éããããŸãã ãã©ãŠã¶ãŒã¯ããããã³ã°ã«ãã£ãŠããŒãããããã¡ã€ã«ã«UTF-8æåã衚瀺ããŸããã
ã³ã³ãã€ã©ã¯ããã«æªãã§ããããªã«æåã¯ãšã©ãŒã§ãããšèŠãªããããããã³ã³ãã€ã«åã«åé€ããå¿ èŠããããŸãïŒå¯èœãªå ŽåïŒã
ãªãã·ã§ã³2ïŒJSMinã®GruntJSã¿ã¹ã¯
ãã§ã«Grunt.jsã䜿çšããŠãããžã§ã¯ããæ§ç¯ããŠããå ŽåãJSMinããã°ã©ã ã®ã³ãŒãã«ãŒãã«åœ¹ç«ã¡ãŸãã ã³ãŒãã¯çž®å°ãããã ãã§ãªããã³ãŒãã«ãŒããäœæãããŸãã ïŒ
Grunt
ããŒãžã§ã³0.4ã®åäœã¯ãèšäºã§èª¬æãããŠããããŒãžã§ã³0.3ãšã¯ç°ãªãããšã«æ³šæããŠãã ããã-泚ïŒ
æé ã¯ã
Grunt
ã䜿çšããŠ
JSMin
ãã©ã°ã€ã³ã§æé©åãããããŒãžã§ã³ãäœæããæ¹æ³ã瀺ããŠããŸãã
1.
Grunt
ãã€ã³ã¹ããŒã«ããã
start/
ããã£ã¬ã¯ããªã®ã«ãŒãã«ãã
gruntfile
ãšãã
grunt.js
ã§ïŒ 代æ¿ã®æ°ãã説æ ïŒãå®è¡ããŸãã
$ npm install -g grunt $ npm view grunt version npm http GET https://registry.npmjs.org/grunt npm http 200 https://registry.npmjs.org/grunt 0.3.17 $ grunt init:gruntfile
Grunt 0.4.xã®äœ¿çšæ¹æ³
å€ãããŒãžã§ã³ãã€ã³ã¹ããŒã«ãããŠãããã0.4.xã«ã¢ããã°ã¬ãŒãããå Žåãã€ã³ã¹ããŒã«ããã»ã¹ã¯ç°ãªããŸãã ãŸããGrunt 0.3.xã®å€ãããŒãžã§ã³ãã¢ã³ã€ã³ã¹ããŒã«ããŸãïŒã°ããŒãã«ãšããŠã€ã³ã¹ããŒã«ãããŠããå ŽåïŒã
npm uninstall -g grunt
Grunt 0.4ã§ã®ã¿ã¹ã¯ã®èšå®ã«ã€ããŠè©³ããèŠãŠã¿ãŸããããããã¯é·ãéãäž»èŠãªãã«ãããŒã«ã®1ã€ã«ãªãããã§ãã
çŸåšãæ°ããããŒãžã§ã³ã®Gruntã¢ãžã¥ãŒã«ã¯ããã€ãã®ã¢ãžã¥ãŒã«ã«åå²ãããŠããŸããã«ãŒãã«ãšãã©ã°ã€ã³ã¯ããã¹ãŠã®ã¢ããªã±ãŒã·ã§ã³ã³ãŒããã«ãŒãã«ããåãåºããŸãã ããã€ãã®ã¢ãžã¥ãŒã«ãã€ã³ã¹ããŒã«ã«é¢ä¿ããŠããŸãã
ã°ããŒãã«grunt-cliã¢ãžã¥ãŒã«ãšããŠã³ãã³ãã©ã€ã³ã€ã³ã¿ãŒãã§ã€ã¹ãã€ã³ã¹ããŒã«ããŸãã
npm install -g grunt-cli
ããã¯ãããžã§ã¯ãã§ã¿ã¹ã¯ãéå§ããã®ã«ååã§ã¯ãããŸãã-åãããžã§ã¯ãã§Gruntfileãã¡ã€ã«ã«ã¿ã¹ã¯ãèšè¿°ããå¿ èŠããããŸãã 以åã¯grunt.jsãšåŒã°ããŠããŸããããæ°ããããŒãžã§ã³ã§ã¯Gruntfile.jsãŸãã¯Gruntfile.coffeeã§ãã ãããžã§ã¯ãã®ã«ãŒãã§2çªç®ã«å¿ èŠãªãã¡ã€ã«ã¯ãnpmïŒNode.jsããã±ãŒãžãããŒãžã£ãŒïŒã§äœ¿çšãããäŸåé¢ä¿ã®ãªã¹ããå«ãpackage.jsonã§ãã
åã¿ã¹ã¯ã§ã¯ãããŒã«ã«ã°ã©ã³ãã¢ãžã¥ãŒã«ããããžã§ã¯ããã©ã«ããŒã«ã€ã³ã¹ããŒã«ãããŸãã
ãããã£ãŠãã³ãã³ãã©ã€ã³ã®ãstart /ããã©ã«ããŒã«ç§»åããããã§æå®ãããã³ãã³ããå®è¡ããŸãã 0.3.xããŒãžã§ã³ãšåæ§ã«ãnode_modulesãã©ã«ããŒã衚瀺ããããã®äžã«grunt moduleãã©ã«ããŒã衚瀺ãããŸããnpm install grunt
ãããžã§ã¯ãã®ã¡ã€ã³ã³ãŒãã®æ¡æ£ã¯ã1å°ã®ã³ã³ãã¥ãŒã¿ãŒã§ããŸããŸãªããŒãžã§ã³ã®ãã©ãŠã¶ãŒãå®è¡ã§ããããã«ããããšãç®çãšããŠè¡ãããŸããã grunt-cliã¯ãç®çã®ãããžã§ã¯ããã©ã«ããŒã§ã³ãã³ããèµ·åããåãªãã·ã§ã«ã§ãã ïŒ gruntjs.com/getting-started ïŒ
次ã«ããããžã§ã¯ãã®ã«ãŒãïŒãstart /ãïŒã§Gruntfile.js
ãšpackage.json
ãæºåããŸããpackage.json
ã¯ãããžã§ã¯ãã«é¢é£ä»ããããäŸåé¢ä¿ïŒãã©ã°ã€ã³ãã«ããŒã®ããŒãºïŒãèšè¿°ããŸãã ãã®ãããžã§ã¯ãã§ã¯ã次ã®ããã«èšè¿°ããŸãã
{ "name": "colors", "version": "0.1.0", "devDependencies": { "grunt": "~0.4.1", "grunt-jsmin-sourcemap": "~1.5.6" } }
ããŒãžã§ã³0.3.xã®æ¬¡ã®æ®µèœ2ã®ä»£ããã«ã次ã®ãã®ãå¿ èŠã§ãã
npm install grunt --save-dev
package.json
ãããã¹ãŠã®äŸåé¢ä¿ããã«ã¢ããããŸãã
2. ïŒããŒãžã§ã³0.3.xã®å ŽåïŒã grunt-jsmin-sourcemapãã©ã°ã€ã³ãã€ã³ã¹ããŒã«ããŸã ã ããã«ããã
node_modules/grunt-jsmin-sourcemap
ãäœæãããŸãã
$ npm install grunt-jsmin-sourcemap
3.äœæããã
grunt.js
ç·šéãïŒããŒãžã§ã³0.4ã®å Žå-"start /"ã«
Gruntfile.js
ãäœæããŸãïŒ ã
jsmin-sourcemap
ã®ã¿ãå«ãŸããããã«ã
jsmin-sourcemap
-ã§ããã ãç°¡åã«ããŸãïŒ
module.exports = function(grunt) { grunt.loadNpmTasks('grunt-jsmin-sourcemap'); grunt.initConfig({ 'jsmin-sourcemap': { all: { src: ['scripts/script.js'], dest: 'scripts/script.jsmin-grunt.js', destMap: 'scripts/script.jsmin-grunt.js.map' } } }); grunt.registerTask('default', 'jsmin-sourcemap'); };
4.ã³ãã³ãã©ã€ã³ã«æ»ã£ãŠgruntãå®è¡ããŸãã
E:\Projects\nodeJS\SourceMaps101\start> grunt
ããã«ãããjsmin-sourcemapã¿ã¹ã¯ã
grunt.js
ïŒãŸãã¯
Gruntfile.js
ïŒãã¡ã€ã«ã§äœæãããããã©ã«ãã®ã¿ã¹ã¯ãšããŠå®è¡ãããŸãã çµæãæåããå ŽåïŒ
Running "jsmin-sourcemap:all" (jsmin-sourcemap) task Done, without errors.
次ã«ãäœæè ã®çµæãšç§ãã¡ã®çµæãåºå¥ããããã«ãå®è¡çµæãcomplete-ruãã£ã¬ã¯ããªã«è¿œå ããŸããããã¯äž»ã«æ°ããããŒãžã§ã³ã®Gruntã«ãã£ãŠç°ãªããŸãã ããã¯ãäŸãå®è¡ãããšãã«ãçµæãWindowsã§ååŸããçµæãšæ¯èŒããã®ã«åœ¹ç«ã¡ãŸãã -çŽ
5.çæããããœãŒã¹ãããscript.jsmin-grunt.js.mapãã¡ã€ã«ã«ãœãŒã¹ãã¡ã€ã«ãæžã蟌ãŸããŠããããšã確èªããŸãïŒ
"sources":["script.js"]
ã
ïŒå®éã«ã¯ã
"sources":["scripts/script.js"]
ãããã«ç»é²ãããŠããŸãã
"sources":["scripts/script.js"]
ãªã®ã§ãæã§ä¿®æ£ããå¿ èŠããããŸãã
6.çæãããscript.grunt-jsmin.jsãã¡ã€ã«ãindex.htmlã«æ¥ç¶ãããã©ãŠã¶ãŒã§éãããã«ã
Option B
ã³ã¡ã³ããå€ããŸã ã
ïŒä¿®æ£ãããindex-ru.htmlãã¡ã€ã«ãã¢ã³ã«ãŒã§åŒã³åºãã ãã§ååã§ãïŒ localhost / index-ru.htmlïŒoption = jsminã-ããããTransl ãïŒ
ãã®äŸã§ã¯ããœãŒã¹ãã¡ã€ã«ã®ãããã³ã°ãååŸããŸãã-ã³ã¬ã¯ã¿ãŒã®ã€ã³ã¹ããŒã«ãè¡ã£ãã®ã¯äœã®çç±ã§ããããŸããã§ããã ããã«ç°¡åã«ãªããŸããã¡ã€ã³ããŒã«ã¯ãã±ããã«ãããŸãã
ããã§ãããããã«ãã¢ã»ã³ããªãžã£ã ã芳å¯ããŸããã¢ã»ã³ããªãžã£ã ã䜿çšããå Žåãä¿®æ£ãè¡ãã«ã¯ããµãŒããŒåŽã®ã¹ã¯ãªãããšããŒãžã§ã³ããšã«ä¿®æ£ããå¿ èŠããããŸãã æºåã®åæ段éã«ããããŒã«ã䜿çšãããã®ãããªéçºã§ãããšåæã«ãåžå Žã§ã¯éåžžã«éèŠããããŸãã
Grunt
ãš
jsmin-sourcemap
ããã«ãããã»ã¹ã«ãã£ãŠ2ã€ã®ãã¡ã€ã«ãäœæãããŸããæåŸã«ãããã³ã°ãã¡ã€ã«ãžã®ãªã³ã¯ãå«ãæé©åãããã¹ã¯ãªãããšãã³ãŒãã«ãŒããã¡ã€ã«èªäœã§ãã åã®ããŒãžã§ã³ãšåæ§ã«ããœãŒã¹ã衚瀺ããã«ã¯äž¡æ¹ã®ãã¡ã€ã«ãå¿ èŠã§ãã
ãªãã·ã§ã³3ïŒUglifyJS
UglifyJS2ã¯ããã1ã€ã®JSãªããã£ãã€ã¶ãŒå§çž®ããã°ã©ã ã§ãã åè¿°ã®2ã€ã®å Žåãšåæ§ã«ãæé©åãããã¹ã¯ãªãããã¡ã€ã«ãäœæãããã³ãŒãã«ãŒãã®URLãšããããã¡ã€ã«èªäœãè¿œå ãããå§çž®ãããJavaScriptãªãã¬ãŒã¿ãŒãšå ã®JavaScriptãªãã¬ãŒã¿ãŒéã®å¯Ÿå¿ãå«ãŸããŸãã 䜿çšããã«ã¯ãã
start
ããã£ã¬ã¯ããªã§å®è¡ããŸãã
1. uglify-jsã¢ãžã¥ãŒã«ãã€ã³ã¹ããŒã«ããŸãïŒ
nocde_module/uglify-js
ãã£ã¬ã¯ããª
nocde_module/uglify-js
ïŒïŒ
$ npm install uglify-js -g $ npm view uglify-js version 2.2.3 $ cd scripts/
2. ã
scripts
ããã£ã¬ã¯ããªã§ã³ãã³ããå®è¡ããŠãæé©åãããããŒãžã§ã³ãšããããäœæããŸãã
uglifyjs --source-map script.uglify.js.map --output script.uglify.js script.js
ïŒä»åã¯ãæã«ããã·ã£ãŒãããºã ã§ã¯ãªãããã¹ãŠãæ©èœããŸããïŒ
3.
index.html
ããªãã·ã§ã³Cãªãã·ã§ã³ã®ã³ã¡ã³ããå€ããŸãã
ãªãã·ã§ã³4ïŒCoffeeScript Redux
å·çæç¹ã§ã¯ãJeremy Ashkenasã«ãããªãªãžãã«ã®Coffescriptãã«ãã¯ãããã³ã°ããµããŒãããŠããªãã£ãããããããã³ã°ãæäœããã¯ããŒã³ã䜿çšãããŸããã Coffescript 1.6.1+ã§ã¯ãå ã®èšèªã䜿çšã§ããŸãïŒãã ããã¯ããŒã³ã®ä»ã®å©ç¹ã¯æžããŸããïŒã
ã¡ãªã¿ã«ããã®ã¯ããŒã³ã¯ã Kickstarterã§ã®ãããªãéçºã®ã¿ãŒã²ãããšããŠå®£èšããã1äž2,000ãã«ãæ£åžžã«åéããŸãã ã
æåã®3ã€ã®ãªãã·ã§ã³ã§ã¯ã1ã€ã®æé©åã¹ãããã®ã¿ãå¿ èŠã§ããã CoffeeScriptã®ãããªèšèªã®å ŽåãCoffeeScriptããJavaScriptãžããããŠæé©åãããJSãžã®2ã€ã®ã¹ããããå¿ èŠã§ãã CoffeeScriptãšCoffeeScript Reduxã³ã³ãã€ã©ãããã«ãã¬ãã«ã³ãŒãã«ãŒããäœæããæ¹æ³ãèŠãŠã¿ãŸãããïŒå ã®Coffeescriptã¯ããŒãžã§ã³1.6.1ãŸã§ã®ã«ãŒãããµããŒãããŠããªãã£ãããã§ã-çŽTranslãïŒ ã
ã¹ããã1ïŒCoffeeScriptããã·ã³ãã«ãªJavaScriptãž
ã³ãã³ãã©ã€ã³ã®ã
start
ããã£ã¬ã¯ããªã«ç§»åããŸãã 次ã®æé ã§ã¯ãæé©åããããã¡ã€ã«ãšãœãŒã¹ã³ãŒããã¡ã€ã«ã®éã®éä¿¡ãã¡ã€ã«ãäœæããŸãã
1.ã°ããŒãã«ã³ãŒã«æ©èœã®-gãªãã·ã§ã³ã䜿çšããŠCoffeeScriptãã€ã³ã¹ããŒã«ããŸãã
2.åçŽãªJSã§
script.coffee.coffee
ãã³ã³ãã€ã«ã
script.coffee.coffee
ã
$ coffee -c scripts/script.coffee.coffee
3. CoffeeScript Reduxãã€ã³ã¹ããŒã«ããŸãã
$ git clone https://github.com/michaelficarra/CoffeeScriptRedux.git coffee-redux $ cd coffee-redux $ npm install $ make -j test $ cd ..
4.ãã¬ãŒã³JSãšå ã®CoffeeScriptéã®å¯Ÿå¿ãèšè¿°ãã
script.coffee.js.map
ãããã³ã°
script.coffee.js.map
ãäœæããŸãã
$ coffee-redux/bin/coffee --source-map -i scripts/script.coffee.coffee > scripts/script.coffee.js.map
5.
script.coffee.js
ãã¡ã€ã«ã®æåŸãã³ãŒãã«ãŒãã®URLã§ããããšã確èªããŸãã
//@ sourceMappingURL=script.coffee.js.map
6.
script.coffee.js.map
ãã¡ã€ã«ã«æ£ãããã¡ã€ã«ãªã³ã¯ãããããšã確èªããŸãã
"file":"script.coffee.coffee", and source file as "sources":["script.coffee.coffee"]
Coffeescriptã䜿çšãã
ã³ãŒããŒã¹ã¯ãªããã¯ããŒã³ã䜿çšãã代ããã«ãå ã®ã³ã³ãã€ã©ã䜿çšããŠäŸãäœæããŸãã
ãã©ã°ã©ã1ããã³2-å€æŽãããªããŸãŸã§ãã
ãã€ã³ã3-ã¹ãããã
4ã
coffee -o script.c -cm script.coffee.coffee
ïŒã-cmãã¯ã--compileãããã³ã--mapããªãã·ã§ã³ã®çç¥åœ¢ã§ããïŒ
5.éèã
åºåãã¡ã€ã«ã®äœæ-ã»ãã®2ã3ã®ãã°ã 1ïŒscript.coffee.jsãã¡ã€ã«ã¯äœæãããŸãã-代ããã«script.jsã§ãããæåã®äŸã®ããªã¢ã³ããäžæžãããŸãã ãããã£ãŠãå¥ã®ãã£ã¬ã¯ããªã«ãã¡ã€ã«ãäœæããŸãïŒOSã§ã¹ããªãŒã ãèæ ®ããªãå Žåã1ã€ã®ã³ãã³ãã®ãã¬ãŒã ã¯ãŒã¯å ã§å¥ã®ååã®ãã¡ã€ã«ãäœæããæ¹æ³ã¯ãããŸããïŒã 2ïŒãã£ã¬ã¯ããªããªãå Žåããå·Šãã®ç©ºã®ãã£ã¬ã¯ããªã/ -p /ããå¿ èŠãªãã£ã¬ã¯ããªãšãšãã«äœæãããŸãã
ãã¹ã確èªããã«ã¯ããã®äžéçµæãå®è¡ãã䟡å€ããããŸããããã¯ã6çªç®ã®äŸïŒéå§çž®ã®ã³ãŒããŒã¹ã¯ãªããïŒã®ããã«èŠãããã®äžã®ãã¹ã®æ£ç¢ºãã確èªããŸãã
1ã€ã®ã³ãã³ãïŒ2ã€ã®åå¥ã®ã³ãã³ãã§ã¯ãªãïŒã§ã³ãŒãããããäœæãããšãã³ã³ãã€ã«ããããã¡ã€ã«ã®æåŸã«æ¬¡ã®åœ¢åŒã®ã³ã¡ã³ãããããŸãã
Chromeã¯ãã®çš®ã®ã³ã¡ã³ããèªã¿åãããšãå€æããŸããã
/* //@ sourceMappingURL=script.map */
ãŸããããã¡ã€ã«ãïŒãscript.jsãããã³ã³ãŒãã«ãŒãå ã®ä»ã®ãã¹ãå€æŽããå¿ èŠã¯ãããŸããã§ããã ãããŸãïŒ
"file": "script.js", "sourceRoot": "..", "sources": [ "script.coffee.coffee" ],
éå§ããããã«ã圌ãã¯ãã®ãããªå¥åŠãªãã£ã¬ã¯ããªåãscript.cãäºåã«éžæããŠã以åã«æ§ç¯ãããã¹ã¯ãªããã«ããŸãé©åããããã«ããŸããã
var lHash = location.hash.substr(1).split('='); if(lHash && lHash.length ==2 && lHash[0] =='option') var optionName = lHash[1]; if(optionName && !parseInt(optionName)) optionName = {closure:1,jsmin:2,uglifyjs:3,coffeescript:4,typescript:5,'coff':6}[optionName.toLowerCase()]; console.log(optionName); optionName = optionName ||0; var loadScript; (loadScript = function(i){ var scr = document.createElement('SCRIPT'); scr.setAttribute('type', 'application/javascript'); scr.src ='scripts/script.'+ ('|closure|jsmin-grunt|uglify|coffee.min|typescript.min|c/script'.split('|')[i]) +(i?'.':'') +'js'; document.getElementsByTagName('head')[0].appendChild(scr); })(optionName);
ãã©ã¡ãŒã¿ãŒ6ãŸãã¯scripts/script.c/script.js
ãããšããã¹scripts/script.c/script.js
ããscripts/script.c/script.js
ãèªã¿åãããŸãã ãã£ã¬ã¯ããªã«äžéãã¡ã€ã«ãäœæããŠãããã¹ãŠãããããªãã§æ©èœããããšãããããŸãã è¯ãã³ã³ãã€ã©äœæè ïŒ
ããã¯ãChromeã®ãããã°ã§ã³ãŒããŒã¹ã¯ãªãããã©ã®ããã«èŠãããã§ãã
Chromeã¯ãŸã utf-8ããŸã£ããç解ããŠããªãããšãããããŸããscr.setAttribute('charset', 'utf-8');
å©ãã«ããªããŸããã
ã¹ããã2ïŒåçŽãªJavaScriptããçž®å°ãããJSãž
1.æåŸã«ãUglifyJSã䜿çšããŠJSãå§çž®ããã³ãŒãã«ãŒããäœæããŸãã ä»åã¯ãã³ã¬ã¯ã¿ãŒãCoffeeScriptã³ãŒãã«ãŒããåãå ¥ããŠããœãŒã¹ã³ãŒãã«ã¢ã¯ã»ã¹ã§ããããã«ããŸãã ã
scripts
ãã§ã³ãã³ããå®è¡ããŸãã
$ cd scripts/ $ uglifyjs script.coffee.js -o script.coffee.min.js --source-map script.coffee.min.js.map --in-source-map script.coffee.js.map
äŸã®ãã©ã³ãã§ã¯ãã³ãã³ãã®ã¿ã€ãã¯
uglifyjs script.c/script.js -o script.coffee.min.js --source-map script.coffee.min.js.map --in-source-map script.c/script.map
2.ã³ãŒãã«ãŒããã¡ã€ã«ã«ãã©ãŒã ã®æ£ãããªã³ã¯ãããããšã確èªããŸã
"file":"script.coffee.min.js"
...ããã³ãã©ãŒã ã®ãœãŒã¹ã³ãŒããžã®æ£ãããªã³ã¯
"sources":["script.coffee.coffee"]
ã¢ãã¬ã¹ããŒã«æžã蟌ã¿ãŸã
http://localhost/#option=coffeescript
...ãããŠããã¡ã€ã«å ã®ãã¹ã«åé¡ãããããšãããããŸãã"sources":["script.coffee.coffee"]
ã¯åäœããã¯ãã§ãããåäœããŸããã§ããã ããããæžã蟌ã¿ã§ãœãŒã¹ãã¡ã€ã«ã衚瀺ããããšãã§ããŸããïŒãã©ãŠã¶ãå床éãå¿ èŠããããŸããïŒ
"sources":["/scripts/script.coffee.coffee"]
ããã§ããscript.c
ãã£ã¬ã¯ããªã®è€éãªãã¹ãscript.c
ããã³ãã«å ã®ãããã¡ã€ã€ããã®ããã«æ©èœããªãã£ããããç·šéããå¿ èŠãããããã®ç·šéã¯çã®è£œåã®ãããã³ã°ã®ããã«èŠããŸãã
ãªãã·ã§ã³5ïŒTypeScript
TypeScriptã¯ãCoffeeScriptãšåæ§ã«ã2ã€ã®ã¹ããããå¿ èŠãšããŸãïŒTypeScript-> simple JavaScript-> minified JavaScriptã ã¹ã¯ãªããã¯jQueryãã©ã°ã€ã³ã䜿çšããããã
script.typescript.ts
ããã³
jquery.d.ts
ãšããååã®2ã€ã®TypeScriptãã¡ã€ã«ãå¿ èŠ
jquery.d.ts
ã
ã¿ã€ãã¹ã¯ãªããã®ã€ã³ã¹ããŒã«ïŒ
npm install -g typescript
ã¹ããã1ïŒTypeScriptããåçŽãªJavaScriptãž
ã³ãã³ãã©ã€ã³ã¢ãŒãã§ã¹ã¯ãªãããã£ã¬ã¯ããªã«ç§»åãã次ãå®è¡ããŸãã
$ tsc script.typescript.ts -sourcemap
ãã®ã³ãã³ãã¯ãæåŸã«ãªã³ã¯ã
script.typescript.js
ãã¡ã€ã«ãäœæããŸãã
//@ sourceMappingURL=script.typescript.js.map
ãããŠãåãã³ãã³ãã§ã script.typescript.js.map
ããããã¡ã€ã«ãäœæãããŸãã
Crhbgnã¯ãjQueryã®ãã©ã¡ãŒã¿ãŒãšã³ãŒãå ã®ãã©ã¡ãŒã¿ãŒã®äžéšã®äžäžèŽã«ã€ããŠäžå¹³ãèšããŸããã
/script.typescript.ts(7,8ïŒïŒããããã£ãkeyCodeãã¯ã¿ã€ããJQueryEventObjectãã®å€ã«ååšããŸãã
ãããã圌ã¯ä»äºãåãå ¥ããŸããã JavaScriptãå®éã«åŠçãããã¡ã€ã«ã
ãœãŒã¹ã³ãŒãã®å€æŽã確èªããã«ã¯ããã©ãŠã¶ã®ãã£ãã·ã¥ãã¯ãªã¢ããå¿ èŠããããŸãã
ã¹ããã2ïŒåçŽãªJavaScriptããçž®å°ãããJSãž
CoffeweScriptãšåæ§ã«ã次ã®ã¹ãããã§ã¯UglifyJSã䜿çšããŸãã
$ uglifyjs script.typescript.js -o script.typescript.min.js --source-map script.typescript.min.js.map --in-source-map script.typescript.js.map
index.html
å ã®ãªã³ã¯ãæ£ããã¹ã¯ãªãããã¡ã€ã«ïŒ
scripts/script.typescript.min.js
ãŠããããšã確èªãããã©ãŠã¶ãŒã§éããŸãã
ãã®åçŽãªã³ãŒãã§ã¯ãã³ã³ãã€ã©ãšãããã¡ã€ã€ã«é¢é£ãããšã©ãŒã¯æ€åºãããŸããã§ããã ãœãŒã¹ã³ãŒããšãããã³ã°ã¯ããµãŒãã¹ãã¡ã€ã«ãæåã§ç·šéããªããŠãæ©èœããŸãã
SASSã®ã³ãŒãã«ãŒã
JavaScriptã«å ããŠãChromeã¯çŸåšãã³ãŒãã«ãŒãçšã«SASSãšSCSSããµããŒãããŠããŸãã SASSãããã³ã°ã®å ŽåãChromeã§ããã€ãã®èšå®ãå€æŽãããããã°ãªãã·ã§ã³ã䜿çšããŠSASSãCSSã«ã³ã³ãã€ã«ããŸãã
1.èšå®ãå€æŽããåã«ãéçºè ããŒã«ãŠã£ã³ããŠããèŠçŽ ã芳å¯ãããšãCSSãžã®ãªã³ã¯ã®ã¿ã衚瀺ãããããšã«æ³šæããŠãã ããã ããã¯å¿ èŠãªãã®ã§ã¯ãããŸããã
2. chromeïŒ// flags /ã«ç§»åããŸãã
3. ã éçºè ããŒã«ã®å®éšãæå¹ã«ããããã€ã³ã¹ããŒã«ããŸãïŒãã·ã¢èªçã®Chrome-ãå®éšçãªéçºè ããŒã«ãæå¹ã«ãããïŒã
Windowsã®å ŽåïŒ
4.
Dev Tools -> Setting -> Experiments -> Check âSupport for SASSâ
ãŸãã
Windowsã®å ŽåïŒ
èšå®ïŒâ°ïŒ->ããŒã«->éçºè ããŒã«->èšå®ïŒå³äžé ã®â£ïŒ->å®éš-> Sassã®ãµããŒã ã
5.ã³ãã³ãã©ã€ã³ã®ã
styles
ããã£ã¬ã¯ããªã§ããã®ãããªãããã°ãªãã·ã§ã³ã䜿çšããŠSASS ãã³ã³ãã€ã«ããŸãã ããã¯ãåã«ãŒã«ã»ããã®åã«
@media -sass-debug-info
$ cd styles/ $ sass --debug-info --watch style.sass:style.css
6. [éçºããŒã«]ãŠã£ã³ããŠãå床éãããããŒãžããªããŒããããããšã確èªããŸãã
7.ããã§ãDev.Toolsã§èŠçŽ ããã§ãã¯ãããšãSASSãã¡ã€ã«ãžã®ã¢ã¯ã»ã¹ã衚瀺ãããŸãã
SASSã衚瀺ããã ãã§ãªããLiveReloadãããã¯ã°ã©ãŠã³ãã§å®è¡ãããŠããå ŽåãSASSãã¡ã€ã«ãå€æŽããããšãããŒãžãå€æŽãããŸãã
次ã«ã Firefoxã§ãããžã§ã¯ããéããFirebugãèŠãŠãã ããã SASSãã¡ã€ã«ã衚瀺ããããšãã§ããŸãã
ã³ãŒãã«ãŒãæ å ±
*.map
ãã¡ã€ã«ãèŠããšããœãŒã¹ãã¡ã€ã«ãšçµæãã¡ã€ã«ã®éã®æ å ±ã®ãããã³ã°ãå«ãŸããŠããŸãã æ§é ã¯ãååãšããŠãããŒãžã§ã³3ã®ãããã®ä»æ§ã«åŸã£ãŠJSON圢åŒã§å«ãŸããŠããŸããéåžžã5ã€ã®ããããã£ããããŸãã
1. ããŒãžã§ã³ ïŒãããã®ããŒãžã§ã³ïŒéåžž3ïŒã
2. file ïŒåºåãã¡ã€ã«ã®ååã
3. sources ïŒãœãŒã¹ãã¡ã€ã«ã®ååã
4. åå ïŒäžèŽã«äœ¿çšãããæåã
5. ãããã³ã° ïŒããŒã¿ãšäžèŽããŸãã
ãµã€ããªã³ã¯
ã³ãŒãã«ãŒãã¯ãŸã 掻çºã«éçºãããŠããŸãããWebã«ã¯ãã§ã«æ³šç®ãã¹ããªãœãŒã¹ãããã€ããããŸãã 詳现ã«ã€ããŠã¯ããããã®ãªã³ã¯ã確èªããŠãã ããã
- Ryan Seddonã«ããJavaScriptãœãŒã¹ãããã®æŠèŠ ãHTML5 Rocksã2012幎3æ21æ¥ã 翻蚳
- ãã¬ãŒã¯ãã€ã³ããšããœãŒã3ïŒ Googleéçºè ããŒã ã«ããJavaScriptãœãŒã¹ããã
- ãã¬ãŒã¯ãã€ã³ããšããœãŒã2ïŒ Google Developer Teamã«ããSASSãœãŒã¹ããã
- ãœãŒã¹ãããã®èšèªãããŒã«ãèšäºã«é¢ãããœãŒã¹ãããwiki
- Ryan Seddonã«ããCoffeeScriptãšTypeScriptã䜿çšãããã«ãã¬ãã«ãœãŒã¹ããã
- ãœãŒã¹ãããããŒãžã§ã³3ã®ææ¡
ãããã«
è€æ°ã®ã³ã³ãã€ã©ã䜿çšããããšã§ãã³ãŒãã«ãŒãã®å¯èœæ§ã瀺ãããããšãé¡ã£ãŠããŸãã çŸåšãæ©èœã¯å¶éãããŠããŸãããå°æ¥çã«ã¯ãå€æ°ãåŒãžã®ã¢ã¯ã»ã¹ã®åœ¢åŒãå«ããå®å šãªãããã°ã®å¯èœæ§ãæåŸ ããçç±ããããŸãã
: Sayanee Basu, . Ruby . â .
, « » â . ; â nodeJS . , , , â , nodeJS. . , , - , , .
( , Firefox .)
? Coffeescript, . , 2 , , JS.
Grunt, , SASS â . , , , . , â , , , .
, , , nodeJS, - .
, Windows + nodeJS.
1) Using Source Maps with TypeScript , Aaron Powell, Oct 3 2012;
2) github.com/mozilla/source-map â This is a library to generate and consume the source map format .
3) Happy debugging with JavaScript source maps by James Allardice, 25 January 2013.
4) bower.io â Twitter.
5) kevinpelgrims.com/blog/2011/12/28/building-coffeescript-with-sublime-on-windows
6) sourcemap.litcoffee .
7) github.com/evanw/node-source-map-support
8) , (2013-05)