Added minification script
parent
995c3ab798
commit
eed9465885
4
Makefile
4
Makefile
|
@ -129,6 +129,10 @@ doc-info: $(PATH_DOC_OUTPUT_INFO)
|
||||||
doc-plain: $(PATH_DOC_OUTPUT_PLAIN)
|
doc-plain: $(PATH_DOC_OUTPUT_PLAIN)
|
||||||
doc-html: $(PATH_DOC_OUTPUT_HTML)/index.html $(PATH_DOC_OUTPUT_HTML1)
|
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 up build dir
|
||||||
clean:
|
clean:
|
||||||
rm -rf "${PATH_BUILD}"
|
rm -rf "${PATH_BUILD}"
|
||||||
|
|
|
@ -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 ) );
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue