From 1a5fe196b3d38b50cbc29179d10a4d3250024342 Mon Sep 17 00:00:00 2001 From: Brandon Frohs Date: Mon, 22 Apr 2013 12:37:12 -0400 Subject: [PATCH 1/2] Add `sourceMapURL` option. Same as `--source-map-url` in CLI. --- tools/node.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/node.js b/tools/node.js index c0dd3dbc..1df61bcd 100644 --- a/tools/node.js +++ b/tools/node.js @@ -52,6 +52,7 @@ for (var i in UglifyJS) { exports.minify = function(files, options) { options = UglifyJS.defaults(options, { outSourceMap : null, + sourceMapURL : null, sourceRoot : null, inSourceMap : null, fromString : false, @@ -110,7 +111,7 @@ exports.minify = function(files, options) { var stream = UglifyJS.OutputStream(output); toplevel.print(stream); return { - code : stream + "", + code : stream + (output.source_map ? "\n//@ sourceMappingURL=" + (options.sourceMapURL || options.outSourceMap) : ""), map : output.source_map + "" }; }; From 9a14825a1a49d24be14b89e8e94c2e78ec6cea2c Mon Sep 17 00:00:00 2001 From: Brandon Frohs Date: Mon, 22 Apr 2013 12:44:31 -0400 Subject: [PATCH 2/2] Add `prefix` option. Same as `-p` and `--prefix` in CLI. --- tools/node.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/node.js b/tools/node.js index 1df61bcd..0bbdf6c6 100644 --- a/tools/node.js +++ b/tools/node.js @@ -59,6 +59,7 @@ exports.minify = function(files, options) { warnings : false, mangle : {}, output : null, + prefix : null, compress : {} }); if (typeof files == "string") @@ -70,6 +71,11 @@ exports.minify = function(files, options) { var code = options.fromString ? file : fs.readFileSync(file, "utf8"); + + if (options.prefix !== null) { + file = file.replace(/^\/+/, "").split(/\/+/).slice(options.prefix).join("/"); + } + toplevel = UglifyJS.parse(code, { filename: options.fromString ? "?" : file, toplevel: toplevel