added support for adding custom paths to source files when passing in strings to uglify

This commit is contained in:
Keith Smith 2014-03-20 12:05:41 -06:00
parent 448a8d3845
commit bcaee279af

View File

@ -59,7 +59,8 @@ exports.minify = function(files, options) {
warnings : false, warnings : false,
mangle : {}, mangle : {},
output : null, output : null,
compress : {} compress : {},
sourcePaths : []
}); });
UglifyJS.base54.reset(); UglifyJS.base54.reset();
@ -72,13 +73,16 @@ exports.minify = function(files, options) {
} else { } else {
if (typeof files == "string") if (typeof files == "string")
files = [ files ]; files = [ files ];
files.forEach(function(file){ files.forEach(function(file, index){
var code = options.fromString var code = options.fromString
? file ? file
: fs.readFileSync(file, "utf8"); : fs.readFileSync(file, "utf8");
var filename = options.fromString
? options.sourcePaths[index] || "?"
: file;
sourcesContent[file] = code; sourcesContent[file] = code;
toplevel = UglifyJS.parse(code, { toplevel = UglifyJS.parse(code, {
filename: options.fromString ? "?" : file, filename: filename,
toplevel: toplevel toplevel: toplevel
}); });
}); });