From 66fd2ece83ea1027b99c78ac0286d32d8a667e01 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Tue, 6 Dec 2011 18:28:56 -0500 Subject: [PATCH] Switched to Closure Compiler This is nothing against uglify. Rather, here's the story on this: Commit e4cd1e fixed an error that was causing minified files to break in IE. This was due to how IE interprets things, not how UglifyJS was minifying them. Indeed, Closure Compiler had the exact same problem. The decision to move to Closure Compiler was due to a variety of factors, which came down to primarily feature set and tests. Closure Compiler is well tested and maintained. It also includes a number of additional, beneficial features. UglifyJS is an excellent project and I would recommend it to anyone, but it is not tested (no unit tests; it's tested by ensuring common libraries like jQuery run after minification). It is, however, significantly faster. It's likely that, in the future, once I add autoconf for the build process to configure certain settings, that I will add UglifyJS as an option. I'm sure many people would prefer that, especially those who dislike Java and do not wish to have it installed. Hopefully those that do decide to install Java will go with openjdk, not Oracle's proprietary implementation. --- .gitignore | 3 +++ Makefile | 19 ++++++++++---- tools/minify.js | 66 ------------------------------------------------- 3 files changed, 17 insertions(+), 71 deletions(-) delete mode 100644 tools/minify.js diff --git a/.gitignore b/.gitignore index e3fbd98..e6b6cf5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ build node_modules + +# downloaded by minification build +tools/compiler.jar diff --git a/Makefile b/Makefile index 9dfb2f8..9b0da39 100644 --- a/Makefile +++ b/Makefile @@ -17,10 +17,11 @@ src_tests := index.js $(shell find "$(path_test)" -name test-* \ path_doc := ./doc -combine=${path_tools}/combine +combine := $(path_tools)/combine +compiler := $(path_tools)/compiler.jar -.PHONY: combine min doc test test-combine +.PHONY: combine min doc test test-combine clean distclean default: combine min @@ -55,10 +56,15 @@ perf: default $(perf_tests) perf-%.js: default @node $@ -min: build/ease.min.js build/ease-full.min.js $(path_build)/browser-test-min.html -build/%.min.js: build/%.js +# minificatino process uses Google Closure compiler +min: build/ease.min.js build/ease-full.min.js $(path_build)/browser-test-min.html \ + | combine +$(compiler): + wget -O- http://closure-compiler.googlecode.com/files/compiler-latest.tar.gz \ + | tar -C $(path_tools) -xzv compiler.jar +build/%.min.js: build/%.js $(compiler) cat $(path_tools)/license.tpl > $@ - node $(path_tools)/minify.js < $< > $@ + java -jar $(compiler) --js $< >> $@ || rm $@ install: doc-info [ -d $(path_info_install) ] || mkdir -p $(path_info_install) @@ -72,3 +78,6 @@ clean: $(MAKE) -C $(path_doc) clean rm -rf "${path_build}" +distclean: clean + rm $(compiler) + diff --git a/tools/minify.js b/tools/minify.js deleted file mode 100644 index 14794d0..0000000 --- a/tools/minify.js +++ /dev/null @@ -1,66 +0,0 @@ -/** - * Minification script - * - * Takes input from stdin, mangles and minifies it, then outputs to stdout. - * ex: $ node minify.js < source.js > source.min.js - */ - -// uses UglifyJS -var uglify, - FILE_ROOT = '../build/'; - -try -{ - // attempt to load UglifyJS - var uglify = require( 'uglify-js' ); -} -catch ( e ) -{ - // if there's a problem loading it, let the user know what they probably - // need to do - process.stderr.write( - "Unable to located UglifyJS. Please run:\n\n" + - " $ npm install uglify-js\n\n" + - "and then try again.\n" - ); - - process.exit( 1 ); -} - -var parser = uglify.parser, - uglify = uglify.uglify; - -// we should receive the file via stdin -var data = ''; -process.stdin - .on( 'data', function( chunk ) - { - data += chunk; - } ) - .on( 'end', function() - { - minify(); - } ) -; - -// stdin is paused by default, so we have to unpause it to read -process.stdin.setEncoding( 'utf8' ) -process.stdin.resume() - - -/** - * Minifies and outputs the code - * - * The process involves mangling the code and minifying it. - */ -function minify() -{ - var ast = parser.parse( data ); - - // mange and minify - ast = uglify.ast_squeeze( ast ); - - // output final, compressed code - process.stdout.write( uglify.gen_code( ast ) ); -} -