Merge 3d6e857957 into 448a8d3845
This commit is contained in:
commit
d0a06e6f44
|
|
@ -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
|
`result.map`. The value passed for `outSourceMap` is only used to set the
|
||||||
`file` attribute in the source map (see [the spec][sm-spec]).
|
`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:
|
You can also specify sourceRoot property to be included in source map:
|
||||||
```javascript
|
```javascript
|
||||||
var result = UglifyJS.minify([ "file1.js", "file2.js", "file3.js" ], {
|
var result = UglifyJS.minify([ "file1.js", "file2.js", "file3.js" ], {
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,8 @@ exports.minify = function(files, options) {
|
||||||
warnings : false,
|
warnings : false,
|
||||||
mangle : {},
|
mangle : {},
|
||||||
output : null,
|
output : null,
|
||||||
compress : {}
|
compress : {},
|
||||||
|
sourcePaths : []
|
||||||
});
|
});
|
||||||
UglifyJS.base54.reset();
|
UglifyJS.base54.reset();
|
||||||
|
|
||||||
|
|
@ -72,13 +73,16 @@ exports.minify = function(files, options) {
|
||||||
} else {
|
} else {
|
||||||
if (typeof files == "string")
|
if (typeof files == "string")
|
||||||
files = [ files ];
|
files = [ files ];
|
||||||
files.forEach(function(file){
|
files.forEach(function(file, index){
|
||||||
var code = options.fromString
|
var code = options.fromString
|
||||||
? file
|
? file
|
||||||
: fs.readFileSync(file, "utf8");
|
: fs.readFileSync(file, "utf8");
|
||||||
|
var filename = options.fromString
|
||||||
|
? options.sourcePaths[index] || "?"
|
||||||
|
: file;
|
||||||
sourcesContent[file] = code;
|
sourcesContent[file] = code;
|
||||||
toplevel = UglifyJS.parse(code, {
|
toplevel = UglifyJS.parse(code, {
|
||||||
filename: options.fromString ? "?" : file,
|
filename: filename,
|
||||||
toplevel: toplevel
|
toplevel: toplevel
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user