feat: add option.outFileName for JS API, if absense, sourceMap.file field will deduced
This commit is contained in:
committed by
Richard van Velzen
parent
2a9989dd18
commit
0a35acbbe7
@@ -11,6 +11,14 @@ describe("Input file as map", function() {
|
|||||||
var map = JSON.parse(result.map);
|
var map = JSON.parse(result.map);
|
||||||
assert.strictEqual(result.code, 'var foo={x:1,y:2,z:3};');
|
assert.strictEqual(result.code, 'var foo={x:1,y:2,z:3};');
|
||||||
assert.deepEqual(map.sources, ['/scripts/foo.js']);
|
assert.deepEqual(map.sources, ['/scripts/foo.js']);
|
||||||
|
assert.strictEqual(map.file, undefined);
|
||||||
|
|
||||||
|
result = Uglify.minify(jsMap, {fromString: true, outFileName: 'out.js'});
|
||||||
|
assert.strictEqual(result.map, null);
|
||||||
|
|
||||||
|
result = Uglify.minify(jsMap, {fromString: true, outFileName: 'out.js', outSourceMap: true});
|
||||||
|
map = JSON.parse(result.map);
|
||||||
|
assert.strictEqual(map.file, 'out.js');
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should accept array of objects and strings", function() {
|
it("Should accept array of objects and strings", function() {
|
||||||
|
|||||||
@@ -63,13 +63,14 @@ describe("minify", function() {
|
|||||||
describe("inSourceMap", function() {
|
describe("inSourceMap", function() {
|
||||||
it("Should read the given string filename correctly when sourceMapIncludeSources is enabled (#1236)", function() {
|
it("Should read the given string filename correctly when sourceMapIncludeSources is enabled (#1236)", function() {
|
||||||
var result = Uglify.minify('./test/input/issue-1236/simple.js', {
|
var result = Uglify.minify('./test/input/issue-1236/simple.js', {
|
||||||
outSourceMap: "simple.js.min.map",
|
outSourceMap: "simple.min.js.map",
|
||||||
inSourceMap: "./test/input/issue-1236/simple.js.map",
|
inSourceMap: "./test/input/issue-1236/simple.js.map",
|
||||||
sourceMapIncludeSources: true
|
sourceMapIncludeSources: true
|
||||||
});
|
});
|
||||||
|
|
||||||
var map = JSON.parse(result.map);
|
var map = JSON.parse(result.map);
|
||||||
|
|
||||||
|
assert.equal(map.file, 'simple.min.js');
|
||||||
assert.equal(map.sourcesContent.length, 1);
|
assert.equal(map.sourcesContent.length, 1);
|
||||||
assert.equal(map.sourcesContent[0],
|
assert.equal(map.sourcesContent[0],
|
||||||
'let foo = x => "foo " + x;\nconsole.log(foo("bar"));');
|
'let foo = x => "foo " + x;\nconsole.log(foo("bar"));');
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ exports.minify = function(files, options) {
|
|||||||
options = UglifyJS.defaults(options, {
|
options = UglifyJS.defaults(options, {
|
||||||
spidermonkey : false,
|
spidermonkey : false,
|
||||||
outSourceMap : null,
|
outSourceMap : null,
|
||||||
|
outFileName : null,
|
||||||
sourceRoot : null,
|
sourceRoot : null,
|
||||||
inSourceMap : null,
|
inSourceMap : null,
|
||||||
sourceMapUrl : null,
|
sourceMapUrl : null,
|
||||||
@@ -120,7 +121,8 @@ exports.minify = function(files, options) {
|
|||||||
}
|
}
|
||||||
if (options.outSourceMap || options.sourceMapInline) {
|
if (options.outSourceMap || options.sourceMapInline) {
|
||||||
output.source_map = UglifyJS.SourceMap({
|
output.source_map = UglifyJS.SourceMap({
|
||||||
file: options.outSourceMap,
|
// prefer outFileName, otherwise use outSourceMap without .map suffix
|
||||||
|
file: options.outFileName || (typeof options.outSourceMap === 'string' ? options.outSourceMap.replace(/\.map$/i, '') : null),
|
||||||
orig: inMap,
|
orig: inMap,
|
||||||
root: options.sourceRoot
|
root: options.sourceRoot
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user