From a9aa85517fa4f6fe968562172396431769f81dc9 Mon Sep 17 00:00:00 2001 From: Yotam Spenser Date: Wed, 6 Jul 2016 13:02:07 +0300 Subject: [PATCH 1/4] Source map URL override from programmatic API --- tools/node.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/node.js b/tools/node.js index 2ee7df21..e1e6d689 100644 --- a/tools/node.js +++ b/tools/node.js @@ -43,6 +43,7 @@ exports.minify = function(files, options) { outSourceMap : null, sourceRoot : null, inSourceMap : null, + sourceMapUrl : null, fromString : false, warnings : false, mangle : {}, @@ -136,8 +137,9 @@ exports.minify = function(files, options) { var stream = UglifyJS.OutputStream(output); toplevel.print(stream); - if (options.outSourceMap && "string" === typeof options.outSourceMap) { - stream += "\n//# sourceMappingURL=" + options.outSourceMap; + var mappingUrlPrefix = "\n//# sourceMappingURL="; + if (options.outSourceMap && typeof options.outSourceMap === "string") { + stream += mappingUrlPrefix + (typeof options.sourceMapUrl === "string" ? options.sourceMapUrl : options.outSourceMap); } var source_map = output.source_map; From 0ae7c36a393da5c27a8da00702960504ce680a08 Mon Sep 17 00:00:00 2001 From: qyoz Date: Mon, 11 Jul 2016 12:41:49 +0300 Subject: [PATCH 2/4] added no source map comment option to progammatic api --- tools/node.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/node.js b/tools/node.js index e1e6d689..20ecb473 100644 --- a/tools/node.js +++ b/tools/node.js @@ -138,7 +138,7 @@ exports.minify = function(files, options) { toplevel.print(stream); var mappingUrlPrefix = "\n//# sourceMappingURL="; - if (options.outSourceMap && typeof options.outSourceMap === "string") { + if (options.outSourceMap && typeof options.outSourceMap === "string" && options.sourceMapUrl !== false) { stream += mappingUrlPrefix + (typeof options.sourceMapUrl === "string" ? options.sourceMapUrl : options.outSourceMap); } From b27e9655adf0b6acd30adfc04bd6efeea5542cf4 Mon Sep 17 00:00:00 2001 From: qyoz Date: Mon, 11 Jul 2016 12:54:19 +0300 Subject: [PATCH 3/4] updated sourceMapUrl docs --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 3245d404..0d6e619a 100644 --- a/README.md +++ b/README.md @@ -663,6 +663,17 @@ var result = UglifyJS.minify("compiled.js", { The `inSourceMap` is only used if you also request `outSourceMap` (it makes no sense otherwise). +To set the source map url, use the `sourceMapUrl` option. +If you're using the X-SourceMap header instead, you can just set the `sourceMapUrl` option to false. +Defaults to outSourceMap: + +```javascript +var result = UglifyJS.minify([ "file1.js" ], { + outSourceMap: "out.js.map", + sourceMapUrl: "localhost/out.js.map" +}); +``` + Other options: - `warnings` (default `false`) — pass `true` to display compressor warnings. From 95f115f50201f7a5517ff878a995006f970e7d24 Mon Sep 17 00:00:00 2001 From: qyoz Date: Mon, 11 Jul 2016 13:08:50 +0300 Subject: [PATCH 4/4] updated the docs regarding source maps with the fromString option issue #1192 --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 0d6e619a..04b0799e 100644 --- a/README.md +++ b/README.md @@ -628,6 +628,14 @@ console.log(result.code); // minified output console.log(result.map); ``` +To generate a source map with the fromString option, you can also use an object: +```javascript +var result = UglifyJS.minify({"file1.js": "var a = function () {};"}, { + outSourceMap: "out.js.map", + fromString: true +}); +``` + Note that the source map is not saved in a file, it's just returned in `result.map`. The value passed for `outSourceMap` is only used to set the `file` attribute in the source map (see [the spec][sm-spec]).