This commit is contained in:
ksmithut 2014-03-20 18:20:08 +00:00
commit d0a06e6f44
2 changed files with 16 additions and 3 deletions

View File

@ -444,6 +444,15 @@ 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]).
You can also pass in an array of file contents to minify, as well as an array of the relative file paths to include in the source map:
```javascript
var result = UglifyJS.minify(["function () {/* ... */}"], {
outSourceMap: "out.js.map",
sourcePaths: ["some-file.js"]
});
```
Note that the sourcePaths need to be relative to where you end up saving the outSourceMap. The array of file contents also need to match up with the sourcePaths array. This functionality has only found itself useful in certain build processes.
You can also specify sourceRoot property to be included in source map:
```javascript
var result = UglifyJS.minify([ "file1.js", "file2.js", "file3.js" ], {

View File

@ -59,7 +59,8 @@ exports.minify = function(files, options) {
warnings : false,
mangle : {},
output : null,
compress : {}
compress : {},
sourcePaths : []
});
UglifyJS.base54.reset();
@ -72,13 +73,16 @@ exports.minify = function(files, options) {
} else {
if (typeof files == "string")
files = [ files ];
files.forEach(function(file){
files.forEach(function(file, index){
var code = options.fromString
? file
: fs.readFileSync(file, "utf8");
var filename = options.fromString
? options.sourcePaths[index] || "?"
: file;
sourcesContent[file] = code;
toplevel = UglifyJS.parse(code, {
filename: options.fromString ? "?" : file,
filename: filename,
toplevel: toplevel
});
});