diff --git a/src/duk_initjs.js b/src/duk_initjs.js index 5a660507..85e0e097 100644 --- a/src/duk_initjs.js +++ b/src/duk_initjs.js @@ -5,10 +5,10 @@ * compatible for user code when core features are changed, without burdening * the main C code with compatibility stuff. * - * This file goes through UglifyJS to minify it. UglifyJS renames variables, - * removes comments, and is clever enough to drop any "if (false) { ... }" - * blocks altogether, so that's an effective way to disable currently unneeded - * code. + * This file is minified with UglifyJS or the closure compiler. Both will + * rename variables, remove comments, and are clever enough to drop any + * "if (false) { ... }" blocks altogether, so that's an effective way to + * disable currently unneeded code. */ (function(G, D) { diff --git a/util/make_dist.sh b/util/make_dist.sh index 2b1c143f..77077f1c 100644 --- a/util/make_dist.sh +++ b/util/make_dist.sh @@ -211,14 +211,31 @@ for i in \ done # Initjs code: built-in Ecmascript code snippets which are evaluated when -# a new global context is created. UglifyJS is used to compact the source, -# not to obfuscate it (although that happens as an unwanted side effect). +# a new global context is created. UglifyJS or the closure compiler is +# used to compact the source. Obfuscating the code is not a goal, although +# that happens as an unwanted side effect. +# +# Closure compiler --compilation_level ADVANCED_OPTIMIZATIONS breaks some +# of the existing code, so don't use it. -cat \ - src/duk_initjs.js \ +cat src/duk_initjs.js \ | UglifyJS/bin/uglifyjs --ascii --no-dead-code --no-copyright \ - > $DISTSRCSEP/duk_initjs_min.js.tmp -cp $DISTSRCSEP/duk_initjs_min.js.tmp $DISTSRCSEP/duk_initjs_min.js + > $DISTSRCSEP/duk_initjs_uglify.js.tmp +java -jar compiler.jar \ + --warning_level QUIET \ + --language_in ECMASCRIPT5 \ + --compilation_level SIMPLE_OPTIMIZATIONS \ + src/duk_initjs.js \ + > $DISTSRCSEP/duk_initjs_closure.js.tmp + +INITJS_ORIG=`wc -c < src/duk_initjs.js` +INITJS_UGLIFY=`wc -c < $DISTSRCSEP/duk_initjs_uglify.js.tmp` +INITJS_CLOSURE=`wc -c < $DISTSRCSEP/duk_initjs_closure.js.tmp` +echo "Minified initjs size: original=$INITJS_ORIG, UglifyJS=$INITJS_UGLIFY, closure=$INITJS_CLOSURE" + +# choose which minifier to use +#echo "Using UglifyJS minified version"; cp $DISTSRCSEP/duk_initjs_uglify.js.tmp $DISTSRCSEP/duk_initjs_min.js +echo "Using closure minified version"; cp $DISTSRCSEP/duk_initjs_closure.js.tmp $DISTSRCSEP/duk_initjs_min.js # Autogenerated strings and built-in files # @@ -234,7 +251,7 @@ python src/genbuildparams.py \ python src/genbuiltins.py \ --buildinfo=$DISTSRCSEP/buildparams.json.tmp \ - --initjs-data=$DISTSRCSEP/duk_initjs_min.js.tmp \ + --initjs-data=$DISTSRCSEP/duk_initjs_min.js \ --out-header=$DISTSRCSEP/duk_builtins.h \ --out-source=$DISTSRCSEP/duk_builtins.c \