| 
									
										
										
										
											2014-06-03 14:45:26 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | var RawSource = require("webpack-core/lib/RawSource"); | 
					
						
							| 
									
										
										
										
											2014-07-18 19:31:50 +08:00
										 |  |  | var ModuleFilenameHelpers = require("./ModuleFilenameHelpers"); | 
					
						
							| 
									
										
										
										
											2014-06-03 14:45:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-18 19:31:50 +08:00
										 |  |  | function EvalSourceMapDevToolModuleTemplatePlugin(compilation, sourceMapComment, moduleFilenameTemplate) { | 
					
						
							| 
									
										
										
										
											2014-06-03 14:45:26 +08:00
										 |  |  | 	this.compilation = compilation; | 
					
						
							|  |  |  | 	this.sourceMapComment = sourceMapComment || "//@ sourceMappingURL=[url]"; | 
					
						
							| 
									
										
										
										
											2014-07-18 19:31:50 +08:00
										 |  |  | 	this.moduleFilenameTemplate = moduleFilenameTemplate || "webpack:///[resource-path]?[hash]"; | 
					
						
							| 
									
										
										
										
											2014-06-03 14:45:26 +08:00
										 |  |  | } | 
					
						
							|  |  |  | module.exports = EvalSourceMapDevToolModuleTemplatePlugin; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | EvalSourceMapDevToolModuleTemplatePlugin.prototype.apply = function(moduleTemplate) { | 
					
						
							|  |  |  | 	var self = this; | 
					
						
							|  |  |  | 	moduleTemplate.plugin("module", function(source, module, chunk) { | 
					
						
							| 
									
										
										
										
											2014-12-31 08:38:23 +08:00
										 |  |  | 		if(source.__EvalSourceMapDevTool_Data) | 
					
						
							|  |  |  | 			return source.__EvalSourceMapDevTool_Data; | 
					
						
							| 
									
										
										
										
											2014-06-03 14:45:26 +08:00
										 |  |  | 		var content = source.source(); | 
					
						
							| 
									
										
										
										
											2014-12-29 07:16:58 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-18 06:43:25 +08:00
										 |  |  | 		var sourceMap = source.map(); | 
					
						
							| 
									
										
										
										
											2014-06-03 14:45:26 +08:00
										 |  |  | 		if(!sourceMap) { | 
					
						
							|  |  |  | 			return source; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-01-18 06:43:25 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// Clone (flat) the sourcemap to ensure that the mutations below do not persist.
 | 
					
						
							|  |  |  | 		sourceMap = Object.keys(sourceMap).reduce(function(obj, key) { | 
					
						
							|  |  |  | 			obj[key] = sourceMap[key]; | 
					
						
							|  |  |  | 			return obj; | 
					
						
							|  |  |  | 		}, {}); | 
					
						
							| 
									
										
										
										
											2014-07-18 19:31:50 +08:00
										 |  |  | 		var modules = sourceMap.sources.map(function(source) { | 
					
						
							|  |  |  | 			var module = self.compilation.findModule(source); | 
					
						
							|  |  |  | 			return module || source; | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 		var moduleFilenames = modules.map(function(module) { | 
					
						
							|  |  |  | 			return ModuleFilenameHelpers.createFilename(module, self.moduleFilenameTemplate, this.requestShortener); | 
					
						
							|  |  |  | 		}, this); | 
					
						
							|  |  |  | 		moduleFilenames = ModuleFilenameHelpers.replaceDuplicates(moduleFilenames, function(filename, i, n) { | 
					
						
							|  |  |  | 			for(var j = 0; j < n; j++) | 
					
						
							|  |  |  | 				filename += "*"; | 
					
						
							|  |  |  | 			return filename; | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 		sourceMap.sources = moduleFilenames; | 
					
						
							|  |  |  | 		if(sourceMap.sourcesContent) { | 
					
						
							|  |  |  | 			sourceMap.sourcesContent = sourceMap.sourcesContent.map(function(content, i) { | 
					
						
							|  |  |  | 				return content + "\n\n\n" + ModuleFilenameHelpers.createFooter(modules[i], this.requestShortener); | 
					
						
							|  |  |  | 			}, this); | 
					
						
							| 
									
										
										
										
											2014-06-03 14:45:26 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-07-18 19:31:50 +08:00
										 |  |  | 		sourceMap.sourceRoot = ""; | 
					
						
							|  |  |  | 		sourceMap.file = module.id + ".js"; | 
					
						
							| 
									
										
										
										
											2014-06-03 14:45:26 +08:00
										 |  |  | 		var footer = self.sourceMapComment.replace(/\[url\]/g, "data:application/json;base64," + new Buffer(JSON.stringify(sourceMap)).toString("base64")); | 
					
						
							| 
									
										
										
										
											2014-12-31 08:38:23 +08:00
										 |  |  | 		return source.__EvalSourceMapDevTool_Data = new RawSource("eval(" + JSON.stringify(content + footer) + ");" ); | 
					
						
							| 
									
										
										
										
											2014-06-03 14:45:26 +08:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 	moduleTemplate.plugin("hash", function(hash) { | 
					
						
							|  |  |  | 		hash.update("eval-source-map"); | 
					
						
							|  |  |  | 		hash.update("1"); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }; |