Implemented basic options support for compressor and comments.
Example use:
var result = UglifyJS.minify([files...], {
compressor: {
warnings:false
},
// https://github.com/mishoo/UglifyJS2#keeping-copyright-notices-or-other-comments
comments:true // false, true or "all"
});
This commit is contained in:
parent
a21f3c6cdd
commit
8c6e3f5729
|
|
@ -62,12 +62,45 @@ for (var i in UglifyJS) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.minify = function(files, options) {
|
exports.minify = function(files, options)
|
||||||
|
{
|
||||||
options = UglifyJS.defaults(options, {
|
options = UglifyJS.defaults(options, {
|
||||||
outSourceMap : null,
|
outSourceMap : null,
|
||||||
inSourceMap : null,
|
inSourceMap : null,
|
||||||
warnings : false,
|
warnings : false,
|
||||||
|
compressor : null,
|
||||||
|
output : null,
|
||||||
|
comments: false
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var compressorOptions = UglifyJS.defaults(options.compressor, {
|
||||||
|
warnings : false
|
||||||
|
});
|
||||||
|
|
||||||
|
var outputOptions = UglifyJS.defaults(options.output, {
|
||||||
|
comments: false,
|
||||||
|
beautify: false
|
||||||
|
});
|
||||||
|
|
||||||
|
// Got comment option?
|
||||||
|
if (options.comments) {
|
||||||
|
if (/^\//.test(options.comments)) {
|
||||||
|
outputOptions.comments = new Function("return(" + options.comments + ")")();
|
||||||
|
} else if (options.comments == "all") {
|
||||||
|
outputOptions.comments = true;
|
||||||
|
} else {
|
||||||
|
outputOptions.comments = function(node, comment) {
|
||||||
|
var text = comment.value;
|
||||||
|
var type = comment.type;
|
||||||
|
if (type == "comment2") {
|
||||||
|
// preserved multiline comments
|
||||||
|
return /License|license|@preserve|@license|@cc_on/i.test(text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (typeof files == "string")
|
if (typeof files == "string")
|
||||||
files = [ files ];
|
files = [ files ];
|
||||||
|
|
||||||
|
|
@ -83,9 +116,11 @@ exports.minify = function(files, options) {
|
||||||
|
|
||||||
// 2. compress
|
// 2. compress
|
||||||
toplevel.figure_out_scope();
|
toplevel.figure_out_scope();
|
||||||
var sq = UglifyJS.Compressor({
|
|
||||||
warnings: options.warnings,
|
// Toplevel warnings override
|
||||||
});
|
if(options.warnings) compressorOptions.warnings = true;
|
||||||
|
|
||||||
|
var sq = UglifyJS.Compressor(compressorOptions);
|
||||||
toplevel = toplevel.transform(sq);
|
toplevel = toplevel.transform(sq);
|
||||||
|
|
||||||
// 3. mangle
|
// 3. mangle
|
||||||
|
|
@ -103,7 +138,11 @@ exports.minify = function(files, options) {
|
||||||
file: options.outSourceMap,
|
file: options.outSourceMap,
|
||||||
orig: inMap
|
orig: inMap
|
||||||
});
|
});
|
||||||
var stream = UglifyJS.OutputStream({ source_map: map });
|
|
||||||
|
// Add sourcemap to output options
|
||||||
|
outputOptions.source_map = map;
|
||||||
|
|
||||||
|
var stream = UglifyJS.OutputStream(outputOptions);
|
||||||
toplevel.print(stream);
|
toplevel.print(stream);
|
||||||
return {
|
return {
|
||||||
code : stream + "",
|
code : stream + "",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user