Declare a source file when passing in a string.

This commit is contained in:
陳信屹 2015-09-24 18:52:46 +08:00
parent 20542a37a8
commit 938df1b024

View File

@ -74,12 +74,15 @@ exports.minify = function(files, options) {
if (typeof files == "string") if (typeof files == "string")
files = [ files ]; files = [ files ];
files.forEach(function(file, i){ files.forEach(function(file, i){
var filename = options.fromString
? (typeof file === 'object' ? file.filename : i)
: file;
var code = options.fromString var code = options.fromString
? file ? (typeof file === 'object' ? file.content : file)
: fs.readFileSync(file, "utf8"); : fs.readFileSync(filename, "utf8");
sourcesContent[file] = code; sourcesContent[filename] = code;
toplevel = UglifyJS.parse(code, { toplevel = UglifyJS.parse(code, {
filename: options.fromString ? i : file, filename: filename,
toplevel: toplevel toplevel: toplevel
}); });
}); });