javascript closure compiler

複数ファイルを複数ファイルに出来ないのかな・・・?と思い。

compilerをダウンロード

https://developers.google.com/closure/compiler/

$ cd compiler-latest/
COPYING README compiler.jar

複数ファイルを一つにするには、READMEに書いてある通り

java -jar compiler.jar –js=in1.js –js=in2.js … –js_output_file=out.js

.js:55: WARNING – Suspicious code. This code lacks side-effects. Is there a bug?
reutrn;

普通に使うとエラー検出も出来て便利です。

levelを変更してみる

java -jar ../../compiler-latest/compiler.jar –compilation_level ADVANCED_OPTIMIZATIONS –js=dev1.js –js=menu.js –js_output_file=out.js
function p(a){var b=[a],c=0;$.b(m,function(g,f){if(f.domain!=a.domain||f.path!=a.path)c++,100<c?reutrn:(b.push(f),console.log(f))});m=b;localStorage.l=JSON.stringify(b);n()}var q=[];
function r(){var a=$(“div#history_thread”),b=”gt;”,c=0;$.b(q,function(a,f){“undefined”!==typeof f.title&&(c++,b+=’gt;gt;’+f.title+”gt;gt;”)});b+=”gt;”;a.c(b);$(“div#history_thread a”).b(function(){$(this).click(function(){var a={domain:$(this).a(“domain”),path:$(this).a(“path”),title:$(this).a(“title”),d:$(this).a(“dat”)};s(a)})});0 "auto"),a.e("overflow-x","hidden"))}function t(a){var b=[a],c=0;$.b(q,function(g,f){if(f.domain!=a.domain||f.path!=a.path||f.d!=a.d)c++,100 var y=j;
function z(){"undefined"!==typeof localStorage.t?(y=JSON.parse(localStorage.t),A()):B();C();window.addEventListener("keydown",function(a){if(!a.metaKey&&!a.ctrlKey&&!a.altKey&&a.shiftKey)switch(a.keyCode){case 72:D("history");break;case 84:D("thread");break;case 73:D("ita_list");break;case 77:D("menu");break;case 78:$("#thread_new")&&$("#thread_new").click();break;case 79:$("#open_option")&&$("#open_option").click();break;case 82:$("#refresh_list")&&$("#refresh_list").click();break;case 76:E&&D(E,
60)}},k)}function D(a,b){if("option"==a)chrome.j.o({type:"openOption"},function(){});else{var c=$("#"+a).D().top;"undefined"!==typeof b&&(c-=b);$("html,body").v({scrollTop:c},"fast")}}

複数ファイルをやる場合は、externsを指定すると使われている定義を変更しないそうで

options.jsをout.jsに出力するとき
java -jar ../../compiler-latest/compiler.jar –compilation_level ADVANCED_OPTIMIZATIONS –js=option.js –externs=base.js –externs=jquery-1.7.2.min.js –js_output_file=out.js
こんな感じで良いのかな?

で適当にこんなスクリプトを書いておく。

import os
jsList = ["option","menu","write","background"]
jsCmdBase = “java -jar ../../compiler-latest/compiler.jar –compilation_level ADVANCED_OPTIMIZATIONS ”
for js in jsList[:]:
jsCmd = jsCmdBase + “–js=” + js + “.js”
for js2 in jsList[:]:
if js != js2 :
jsCmd += ” –externs=”+js2+”.js”
jsCmd += ” –externs=jquery.js”
jsCmd += ” –js_output_file=” + js + “.r.js”
os.system( jsCmd )

https://developers.google.com/closure/compiler/docs/api-tutorial3

今のところ修正しないといけないところや確認が多いので、advanceは使わず。

This entry was posted on 日曜日, 4月 15th, 2012 at 10:31 PM and is filed under Chrome Extention, Javascript. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

Unityによるゲームを公開しております iOS/Android
https://itunes.apple.com/jp/app/lost-knight-3d-action/id900917032
https://play.google.com/store/apps/details?id=com.groundroad.runknight

各種開発支援・機能開発等小さいお仕事などもお請けしております。
unity開発支援, PHPシステム開発, javascript/html5 フロント開発, titanium mobileアプリ開発
お気軽にお問い合わせください
大崎・五反田近郊での対面でのお打ち合わせはいつでも可能です。