update build scripts to work with UglifyJS2

This commit is contained in:
Vladimir Agafonkin 2012-12-12 19:08:57 +02:00
parent 5f467337f6
commit 9fac165906
2 changed files with 13 additions and 9 deletions

View File

@ -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 + ')');

View File

@ -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;
};
};