From 938df1b02442305f55db2a0bd65efd416c2a79ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=B3=E4=BF=A1=E5=B1=B9?= Date: Thu, 24 Sep 2015 18:52:46 +0800 Subject: [PATCH] Declare a source file when passing in a string. --- tools/node.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tools/node.js b/tools/node.js index eba2bc1d..30371c2d 100644 --- a/tools/node.js +++ b/tools/node.js @@ -74,12 +74,15 @@ exports.minify = function(files, options) { if (typeof files == "string") files = [ files ]; files.forEach(function(file, i){ + var filename = options.fromString + ? (typeof file === 'object' ? file.filename : i) + : file; var code = options.fromString - ? file - : fs.readFileSync(file, "utf8"); - sourcesContent[file] = code; + ? (typeof file === 'object' ? file.content : file) + : fs.readFileSync(filename, "utf8"); + sourcesContent[filename] = code; toplevel = UglifyJS.parse(code, { - filename: options.fromString ? i : file, + filename: filename, toplevel: toplevel }); });