From 0e1ef92f4287789fc9ce4c1bad9d4b407081e7b5 Mon Sep 17 00:00:00 2001 From: WalkMe Date: Wed, 21 Jan 2015 16:50:17 +0200 Subject: [PATCH] added comment option for programmatic use --- tools/node.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tools/node.js b/tools/node.js index 4bc8517b..acc78b4f 100644 --- a/tools/node.js +++ b/tools/node.js @@ -61,7 +61,8 @@ exports.minify = function(files, options) { warnings : false, mangle : {}, output : null, - compress : {} + compress : {}, + comments : false }); UglifyJS.base54.reset(); @@ -123,6 +124,25 @@ exports.minify = function(files, options) { } } + + //5. comments + if (options.comments) { + if (/^\//.test(options.comments)) { + output.comments = new Function("return(" + options.comments + ")")(); + } else if (options.comments == "all") { + output.comments = true; + } else { + output.comments = function(node, comment) { + var text = comment.value; + var type = comment.type; + if (type == "comment2") { + // multiline comment + return /@preserve|@license|@cc_on/i.test(text); + } + }; + } + } + if (options.output) { UglifyJS.merge(output, options.output); }