uglify-loader
Advanced tools
Comparing version 1.3.0 to 1.4.0
59
index.js
var UglifyJS = require("uglify-js"); | ||
var loaderUtils = require('loader-utils'); | ||
var sourceMap = require('source-map'); | ||
function mergeSourceMap(map, inputMap) { | ||
var inputMapConsumer = new sourceMap.SourceMapConsumer(inputMap); | ||
var outputMapConsumer = new sourceMap.SourceMapConsumer(map); | ||
var mergedGenerator = new sourceMap.SourceMapGenerator({ | ||
file: inputMapConsumer.file, | ||
sourceRoot: inputMapConsumer.sourceRoot | ||
}); | ||
var source = outputMapConsumer.sources[0]; | ||
inputMapConsumer.eachMapping(function (mapping) { | ||
var generatedPosition = outputMapConsumer.generatedPositionFor({ | ||
line: mapping.generatedLine, | ||
column: mapping.generatedColumn, | ||
source: source | ||
}); | ||
if (generatedPosition.column != null) { | ||
mergedGenerator.addMapping({ | ||
source: mapping.source, | ||
original: mapping.source == null ? null : { | ||
line: mapping.originalLine, | ||
column: mapping.originalColumn | ||
}, | ||
generated: generatedPosition | ||
}); | ||
} | ||
}); | ||
var mergedMap = mergedGenerator.toJSON(); | ||
inputMap.mappings = mergedMap.mappings; | ||
return inputMap | ||
}; | ||
module.exports = function(source, inputSourceMap) { | ||
@@ -8,3 +45,3 @@ var callback = this.async(); | ||
if (this.cacheable) { | ||
this.cacheable(); | ||
this.cacheable(); | ||
} | ||
@@ -19,11 +56,15 @@ | ||
var result = UglifyJS.minify(source, opts); | ||
var sourceFilename = loaderUtils.getRemainingRequest(this); | ||
var current = loaderUtils.getCurrentRequest(this); | ||
var sourceMap = JSON.parse(result.map); | ||
sourceMap.sources = [sourceFilename]; | ||
sourceMap.file = current; | ||
sourceMap.sourcesContent = [source]; | ||
callback(null, result.code, sourceMap); | ||
}; | ||
if (inputSourceMap) { | ||
callback(null, result.code, mergeSourceMap(sourceMap, inputSourceMap)); | ||
} else { | ||
var sourceFilename = loaderUtils.getRemainingRequest(this); | ||
var current = loaderUtils.getCurrentRequest(this); | ||
sourceMap.sources = [sourceFilename]; | ||
sourceMap.file = current; | ||
sourceMap.sourcesContent = [source]; | ||
callback(null, result.code, sourceMap); | ||
} | ||
}; |
{ | ||
"name": "uglify-loader", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "Uglify.js loader for webpack", | ||
@@ -25,4 +25,5 @@ "main": "index.js", | ||
"loader-utils": "^0.2.7", | ||
"source-map": "^0.5.6", | ||
"uglify-js": "^2.4.16" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4818
55
3
+ Addedsource-map@^0.5.6