diff --git a/Makefile b/Makefile index e673739..baff32e 100644 --- a/Makefile +++ b/Makefile @@ -129,6 +129,10 @@ doc-info: $(PATH_DOC_OUTPUT_INFO) doc-plain: $(PATH_DOC_OUTPUT_PLAIN) doc-html: $(PATH_DOC_OUTPUT_HTML)/index.html $(PATH_DOC_OUTPUT_HTML1) +min: build/ease.min.js build/ease-full.min.js +build/%.min.js: build/%.js + node $(PATH_TOOLS)/minify.js < $< > $@ + # clean up build dir clean: rm -rf "${PATH_BUILD}" diff --git a/tools/minify.js b/tools/minify.js new file mode 100644 index 0000000..e8ca5db --- /dev/null +++ b/tools/minify.js @@ -0,0 +1,49 @@ +/** + * 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 parser = require( 'uglify-js' ).parser, + uglify = require( 'uglify-js' ).uglify, + + FILE_ROOT = '../build/' +; + +// 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_mangle( ast ); + ast = uglify.ast_squeeze( ast ); + + // output final, compressed code + process.stdout.write( uglify.gen_code( ast ) ); +} +