mirror of https://github.com/webpack/webpack.git
				
				
				
			use sourceAndMap is available
This commit is contained in:
		
							parent
							
								
									76a2fef32a
								
							
						
					
					
						commit
						92f53176a2
					
				|  | @ -17,9 +17,15 @@ EvalSourceMapDevToolModuleTemplatePlugin.prototype.apply = function(moduleTempla | |||
| 	moduleTemplate.plugin("module", function(source, module, chunk) { | ||||
| 		if(source.__EvalSourceMapDevTool_Data) | ||||
| 			return source.__EvalSourceMapDevTool_Data; | ||||
| 		var content = source.source(); | ||||
| 
 | ||||
| 		var sourceMap = source.map(); | ||||
| 		if(source.sourceAndMap) { | ||||
| 			var sourceAndMap = source.sourceAndMap(); | ||||
| 			var sourceMap = sourceAndMap.map; | ||||
| 			var content = sourceAndMap.source; | ||||
| 		} else { | ||||
| 			var sourceMap = source.map(); | ||||
| 			var content = source.source(); | ||||
| 		} | ||||
| 		if(!sourceMap) { | ||||
| 			return source; | ||||
| 		} | ||||
|  |  | |||
|  | @ -63,12 +63,22 @@ SourceMapDevToolPlugin.prototype.apply = function(compiler) { | |||
| 						} | ||||
| 						return; | ||||
| 					} | ||||
| 					var sourceMap = asset.map(); | ||||
| 					if(asset.sourceAndMap) { | ||||
| 						var sourceAndMap = asset.sourceAndMap(); | ||||
| 						var sourceMap = sourceAndMap.map; | ||||
| 						var source = sourceAndMap.source; | ||||
| 					} else { | ||||
| 						var sourceMap = asset.map(); | ||||
| 						var source = asset.source(); | ||||
| 					} | ||||
| 					if(!sourceMap.sources) | ||||
| 						console.log(asset, sourceMap, asset.constructor); | ||||
| 					if(sourceMap) { | ||||
| 						return { | ||||
| 							chunk: chunk, | ||||
| 							file: file, | ||||
| 							asset: asset, | ||||
| 							source: source, | ||||
| 							sourceMap: sourceMap | ||||
| 						} | ||||
| 					} | ||||
|  | @ -112,6 +122,7 @@ SourceMapDevToolPlugin.prototype.apply = function(compiler) { | |||
| 				var file = task.file; | ||||
| 				var asset = task.asset; | ||||
| 				var sourceMap = task.sourceMap; | ||||
| 				var source = task.source; | ||||
| 				var moduleFilenames = task.moduleFilenames; | ||||
| 				var modules = task.modules; | ||||
| 				sourceMap.sources = moduleFilenames; | ||||
|  | @ -144,12 +155,12 @@ SourceMapDevToolPlugin.prototype.apply = function(compiler) { | |||
| 					}); | ||||
| 					var sourceMapUrl = path.relative(path.dirname(file), sourceMapFile).replace(/\\/g, "/"); | ||||
| 					if(currentSourceMappingURLComment !== false) { | ||||
| 						asset.__SourceMapDevTool_Data[file] = this.assets[file] = new ConcatSource(asset, currentSourceMappingURLComment.replace(/\[url\]/g, sourceMapUrl)); | ||||
| 						asset.__SourceMapDevTool_Data[file] = this.assets[file] = new ConcatSource(new RawSource(source), currentSourceMappingURLComment.replace(/\[url\]/g, sourceMapUrl)); | ||||
| 					} | ||||
| 					asset.__SourceMapDevTool_Data[sourceMapFile] = this.assets[sourceMapFile] = new RawSource(JSON.stringify(sourceMap)); | ||||
| 					chunk.files.push(sourceMapFile); | ||||
| 				} else { | ||||
| 					asset.__SourceMapDevTool_Data[file] = this.assets[file] = new ConcatSource(asset, currentSourceMappingURLComment | ||||
| 					asset.__SourceMapDevTool_Data[file] = this.assets[file] = new ConcatSource(new RawSource(source), currentSourceMappingURLComment | ||||
| 						.replace(/\[map\]/g, function() { | ||||
| 							return JSON.stringify(sourceMap); | ||||
| 						}) | ||||
|  |  | |||
|  | @ -32,8 +32,15 @@ LoaderPlugin.prototype.apply = function(compiler) { | |||
| 
 | ||||
| 						if(dep.module.error) return callback(dep.module.error); | ||||
| 						if(!dep.module._source) throw new Error("The module created for a LoaderDependency must have a property _source"); | ||||
| 						var map = dep.module._source.map(); | ||||
| 						var source = dep.module._source.source(); | ||||
| 						var moduleSource = dep.module._source; | ||||
| 						if(moduleSource.sourceAndMap) { | ||||
| 							var sourceAndMap = moduleSource.sourceAndMap(); | ||||
| 							var map = sourceAndMap.map; | ||||
| 							var source = sourceAndMap.source; | ||||
| 						} else { | ||||
| 							var map = moduleSource.map(); | ||||
| 							var source = moduleSource.source(); | ||||
| 						} | ||||
| 						if(dep.module.fileDependencies) { | ||||
| 							dep.module.fileDependencies.forEach(function(dep) { | ||||
| 								loaderContext.addDependency(dep); | ||||
|  | @ -50,4 +57,4 @@ LoaderPlugin.prototype.apply = function(compiler) { | |||
| 			}; | ||||
| 		}); | ||||
| 	}); | ||||
| }; | ||||
| }; | ||||
|  |  | |||
|  | @ -46,13 +46,19 @@ UglifyJsPlugin.prototype.apply = function(compiler) { | |||
| 				var warnings = []; | ||||
| 				try { | ||||
| 					var asset = compilation.assets[file]; | ||||
| 					var input = asset.source(); | ||||
| 					if(asset.__UglifyJsPlugin) { | ||||
| 						compilation.assets[file] = asset.__UglifyJsPlugin; | ||||
| 						return; | ||||
| 					} | ||||
| 					if(options.sourceMap !== false) { | ||||
| 						var inputSourceMap = asset.map(); | ||||
| 						if(asset.sourceAndMap) { | ||||
| 							var sourceAndMap = asset.sourceAndMap(); | ||||
| 							var inputSourceMap = sourceAndMap.map; | ||||
| 							var input = sourceAndMap.source; | ||||
| 						} else { | ||||
| 							var inputSourceMap = asset.map(); | ||||
| 							var input = asset.source(); | ||||
| 						} | ||||
| 						var sourceMap = new SourceMapConsumer(inputSourceMap); | ||||
| 						uglify.AST_Node.warn_function = function(warning) { | ||||
| 							var match = /\[.+:([0-9]+),([0-9]+)\]/.exec(warning); | ||||
|  | @ -67,6 +73,7 @@ UglifyJsPlugin.prototype.apply = function(compiler) { | |||
| 								"[" + requestShortener.shorten(original.source) + ":" + original.line + "," + original.column + "]"); | ||||
| 						}; | ||||
| 					} else { | ||||
| 						var input = asset.source(); | ||||
| 						uglify.AST_Node.warn_function = function(warning) { | ||||
| 							warnings.push(warning); | ||||
| 						}; | ||||
|  | @ -102,7 +109,7 @@ UglifyJsPlugin.prototype.apply = function(compiler) { | |||
| 					if(map) map = map + ""; | ||||
| 					stream = stream + ""; | ||||
| 					asset.__UglifyJsPlugin = compilation.assets[file] = (map ? | ||||
| 						new SourceMapSource(stream, file, map, input, inputSourceMap) : | ||||
| 						new SourceMapSource(stream, file, JSON.parse(map), input, inputSourceMap) : | ||||
| 						new RawSource(stream)); | ||||
| 					if(warnings.length > 0) { | ||||
| 						compilation.warnings.push(new Error(file + " from UglifyJs\n" + warnings.join("\n"))); | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue