From 1a5fe196b3d38b50cbc29179d10a4d3250024342 Mon Sep 17 00:00:00 2001 From: Brandon Frohs Date: Mon, 22 Apr 2013 12:37:12 -0400 Subject: [PATCH 1/4] 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/4] 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 From eda3a19b38c9dda896f273c9988766d76b193ee2 Mon Sep 17 00:00:00 2001 From: Brandon Frohs Date: Sun, 13 Jul 2014 21:30:20 -0400 Subject: [PATCH 3/4] Avoid adding source map url twice --- tools/node.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/node.js b/tools/node.js index 52405f3a..21a202fb 100644 --- a/tools/node.js +++ b/tools/node.js @@ -134,12 +134,14 @@ exports.minify = function(files, options) { var stream = UglifyJS.OutputStream(output); toplevel.print(stream); - if(options.outSourceMap){ + if(options.sourceMapURL){ + stream += "\n//# sourceMappingURL=" + options.sourceMapURL; + } else if(options.outSourceMap){ stream += "\n//# sourceMappingURL=" + options.outSourceMap; } return { - code : stream + (output.source_map ? "\n//@ sourceMappingURL=" + (options.sourceMapURL || options.outSourceMap) : ""), + code : stream + "", map : output.source_map + "" }; }; From 883fb2177e8c08434f77c67a37831cc153d44a8f Mon Sep 17 00:00:00 2001 From: Brandon Frohs Date: Sun, 3 Aug 2014 23:46:06 -0400 Subject: [PATCH 4/4] Add leading / to original's url --- tools/node.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/node.js b/tools/node.js index 21a202fb..6880204d 100644 --- a/tools/node.js +++ b/tools/node.js @@ -80,7 +80,7 @@ exports.minify = function(files, options) { : fs.readFileSync(file, "utf8"); if (options.prefix !== null) { - file = file.replace(/^\/+/, "").split(/\/+/).slice(options.prefix).join("/"); + file = '/' + file.replace(/^\/+/, "").split(/\/+/).slice(options.prefix).join("/"); } sourcesContent[file] = code;