diff --git a/Jakefile.js b/Jakefile.js index baa72ba9..477df8cf 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -1,5 +1,6 @@ var build = require('./build/build.js'), - lint = require('./build/hint.js'); + lint = require('./build/hint.js'), + UglifyJS = require('uglify-js'); var COPYRIGHT = '/*\n Copyright (c) 2010-2012, CloudMade, Vladimir Agafonkin\n' + ' Leaflet is an open-source JavaScript library for mobile-friendly interactive maps.\n' + @@ -51,7 +52,7 @@ task('build', ['lint'], function (compsBase32, buildName) { var path = pathPart + '.js', oldCompressed = build.load(path), - newCompressed = COPYRIGHT + build.uglify(content), + newCompressed = COPYRIGHT + UglifyJS.minify(files, {warnings: true}).code, delta = build.getSizeDelta(newCompressed, oldCompressed); console.log('\tCompressed size: ' + newCompressed.length + ' bytes (' + delta + ')'); diff --git a/build/build.js b/build/build.js index a4da18ae..5e07ea80 100644 --- a/build/build.js +++ b/build/build.js @@ -40,14 +40,17 @@ exports.getFiles = function (compsBase32) { }; exports.uglify = function (code) { - var pro = uglifyjs.uglify; + var toplevel = uglifyjs.parse(code); + toplevel.figure_out_scope(); - var ast = uglifyjs.parser.parse(code); - ast = pro.ast_mangle(ast, {mangle: true}); - ast = pro.ast_squeeze(ast); - ast = pro.ast_squeeze_more(ast); + var compressor = uglifyjs.Compressor(); + var compressed_ast = toplevel.transform(compressor); - return pro.gen_code(ast) + ';'; + compressed_ast.figure_out_scope(); + compressed_ast.compute_char_frequency(); + compressed_ast.mangle_names(); + + return compressed_ast.print_to_string() + ';'; }; exports.combineFiles = function (files) { @@ -76,4 +79,4 @@ exports.getSizeDelta = function (newContent, oldContent) { } var delta = newContent.replace(/\r\n?/g, '\n').length - oldContent.replace(/\r\n?/g, '\n').length; return (delta >= 0 ? '+' : '') + delta; -}; \ No newline at end of file +};