Makeãå©ç¨ããJavaScriptãã¡ã¤ã«ã®çµåã»å§ç¸®
ããç¨åº¦ã®è¦æ¨¡ã®JavaScriptããã°ã©ãã³ã°ã§ã¯ãã¢ã¸ã¥ã¼ã«æ¯ã«ãè¤æ°ã®ãã¡ã¤ã«ã«åå²ãã¦ããã°ã©ãã³ã°ããã®ãæ®éã§ãããããã¯ããã¡ã¤ã«ã®å¤§ãããé©åº¦ãªæ¹ãç·¨éä½æ¥ã容æãªã®ã¨ãã¢ã¸ã¥ã¼ã«ã®å¥ããã¸ã§ã¯ãã¸ã®åå©ç¨æ§ãé«ããããã§ããã
ãããããã©ã¦ã¶ã»ã¢ããªã±ã¼ã·ã§ã³ã§ã¯ãè¤æ°ãã¡ã¤ã«ã1ã¤ã®ãã¡ã¤ã«ã«çµåããæ¹ãæã¾ããããªããªãã°ãè¤æ°ãã¡ã¤ã«ã¸ã®åå²ã¯ããµã¼ãã¸ã®å¤æ°ã®HTTPã³ãã¯ã·ã§ã³ã®çºçãæå³ããå¿çæ§ãä½ä¸ããããã®ãããä¾ãã°ãGoogle Mapsã§ã¯ãå¤æ°ã®ã³ã¼ãã100kbãè¶ ãã1ã¤ã®JavaScriptãã¡ã¤ã«ã«ã¾ã¨ãããã¦ããã
ã¾ããã¦ã¼ã¶ã®å©ä¾¿æ§ãé«ããæå³ã§ã¯ãJavaScriptãã¡ã¤ã«ã®å§ç¸®ãéè¦ã§ãããJavaScriptã®ææ³çãªæå³ã¯ä¿åããã¾ã¾ããã¡ã¤ã«ãµã¤ãºãå§ç¸®ãããã¨ã«ããããã¦ã³ãã¼ãæéãçãã§ãããã¾ããå§ç¸®ã«ãããJavaScriptãã¡ã¤ã«ã®å¯èªæ§ãä½ä¸ããã®ã§ãä»äººãã³ã¼ããèªã¿ã«ãããªãã
ãã®ãããªJavaScriptãã¡ã¤ã«ã®çµåã»å§ç¸®ã¯ãã¦ã¼ã¶ã®å©ä¾¿æ§ãé«ããä¸ã§ã¯éè¦ãªå¦çã«ãããããããæå¤ã¨å®è¡ããã¦ããªããããã¯ãçµåã»å§ç¸®ããã½ã¼ã¹ã®ä¿®æ£æ¯ã«å¿ è¦ãªãããæç¶ãã®é¢åããå«ããã¦ããã®ã ã¨æãã
ã½ã¼ã¹ã®ä¿®æ£æ¯ã«çºçããä½æ¥ãèªååããã«ã¯GNU makeã便å©ã§ãããä¾ãã°ã次ã®2ã¤ã®ãã¡ã¤ã«test1.jsãtest2.jsãããã¨ãããã
//test1.js function MyClass(){ this.foo = function(argument1, argument2){ var addedArgs = parseInt(argument1)+parseInt(argument2); return addedArgs; } var anonymousInnerFunction = function(){ // do stuff here! } } function MyFunc(){ // this is a top-level function } // we've got multiple lines of whitespace here
//test2.js function MyClass2(){ this.bar = function(argument1, argument2){ var addedArgs = parseInt(argument1) * parseInt(argument2); return addedArgs; } }
Makefileã«æ¬¡ã®ããã«è¨è¿°ããã
$ cat Makefile SRC = test1.js test2.js COMB = test.js COMP = small_test.js all: $(COMP) $(COMB): $(SRC) cat $(SRC) > $(COMB) $(COMP): $(COMB) java -jar custom_rhino.jar -c $(COMB) > $(COMP)
ããã¦ãmakeãå®è¡ããã
$ make cat test1.js test2.js > test.js java -jar custom_rhino.jar -c test.js > small_test.js
ãã®çµæãsmall_test.jsãå¾ããããã®å 容ã¯æ¬¡ã¨ãªãã
function MyClass(){ this.foo=function(_1,_2){ var _3=parseInt(_1)+parseInt(_2); return _3; }; var _4=function(){ }; } function MyFunc(){ } function MyClass2(){ this.bar=function(_5,_6){ var _7=parseInt(_5)*parseInt(_6); return _7; }; }
2ã¤ã®jsãã¡ã¤ã«ã1ã¤ã«ãã¡ã¤ã«ã«ã¾ã¨ããããã¾ãããã¡ã¤ã«ãµã¤ãºã549byteãã238byteã¨ãç´ååã«ã¾ã§å§ç¸®ããã¦ããã
makeãç¨ããå©ç¹ã¯ãããããã®ã³ã¼ããä¿®æ£ãããå ´åã®ã¿ãã³ã¼ããå§ç¸®ã»ä¿®æ£ãããç¹ã§ãããåæ§ãªå¦çã¯ã·ã§ã«ã¹ã¯ãªãããªã©ã§ãå®ç¾ã§ããããæ¨æºæè¡ã§ããmakeãå©ç¨ããæ¹ãæ±ç¨æ§ãé«ãã¨æãã
ãªããJavaScriptãã¡ã¤ã«ã®å§ç¸®ã«ã¯Dojo's Compressorãç¨ãããMakefileä¸ã®custom_rhino.jarãããã§ãããDojo's Compressorã§ã¯æ¥æ¬èªæååã¯ãã¾ãæ±ããªããããªã®ã§ãæ¥æ¬èªæååã¯å¥ãã¡ã¤ã«ã«è¨è¿°ããå¿ è¦ããããã¾ããWindowsç°å¢ã§makeãå©ç¨ããã«ã¯ãcygwinã®å°å ¥ãç°¡åã ã¨æãã