[Pkg-javascript-commits] [uglifyjs] 06/49: Source map URL override from programmatic API
Jonas Smedegaard
dr at jones.dk
Fri Dec 9 11:43:24 UTC 2016
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository uglifyjs.
commit af37ecafe1c24e9fb06a371357d10a04446ff71e
Author: Yotam Spenser <yotam.s at walkme.com>
Date: Wed Jul 6 13:02:07 2016 +0300
Source map URL override from programmatic API
---
README.md | 19 +++++++++++++++++++
tools/node.js | 6 ++++--
2 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index 3245d40..04b0799 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]).
@@ -663,6 +671,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.
diff --git a/tools/node.js b/tools/node.js
index 2ee7df2..20ecb47 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" && options.sourceMapUrl !== false) {
+ stream += mappingUrlPrefix + (typeof options.sourceMapUrl === "string" ? options.sourceMapUrl : options.outSourceMap);
}
var source_map = output.source_map;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git
More information about the Pkg-javascript-commits
mailing list