| 
									
										
										
										
											2013-03-11 21:51:23 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2013-03-26 23:54:41 +08:00
										 |  |  | var ConcatSource = require("webpack-core/lib/ConcatSource"); | 
					
						
							|  |  |  | var OriginalSource = require("webpack-core/lib/OriginalSource"); | 
					
						
							| 
									
										
										
										
											2013-03-11 21:51:23 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | function UmdMainTemplateDecorator(mainTemplate, name) { | 
					
						
							|  |  |  | 	this.mainTemplate = mainTemplate; | 
					
						
							|  |  |  | 	this.name = name; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | module.exports = UmdMainTemplateDecorator; | 
					
						
							|  |  |  | UmdMainTemplateDecorator.prototype.render = function(hash, chunk, moduleTemplate, dependencyTemplates) { | 
					
						
							|  |  |  | 	var source = this.mainTemplate.render(hash, chunk, moduleTemplate, dependencyTemplates); | 
					
						
							|  |  |  | 	var prefix = "module.exports =\n"; | 
					
						
							| 
									
										
										
										
											2013-03-26 23:54:41 +08:00
										 |  |  | 	return new ConcatSource(new OriginalSource( | 
					
						
							| 
									
										
										
										
											2013-03-11 21:51:23 +08:00
										 |  |  | 		"(function webpackUniversalModuleDefinition(root) {\n" + | 
					
						
							|  |  |  | 		"	return function webpackUniversalModuleDefinitionWrapBootstrap(fn) {\n" + | 
					
						
							|  |  |  | 		"		return function webpackUniversalModuleDefinitionBootstrap(modules) {\n" + | 
					
						
							|  |  |  | 		"			if(typeof exports === 'object' && typeof module === 'object')\n" + | 
					
						
							|  |  |  | 		"				module.exports = fn(modules);\n" + | 
					
						
							|  |  |  | 		"			else if(typeof define === 'function' && define.amd)\n" + | 
					
						
							|  |  |  | 		"				define(function() { return fn(modules); });\n" + | 
					
						
							|  |  |  | 		"			else if(typeof exports === 'object')\n" + | 
					
						
							|  |  |  | 		"				exports[" + JSON.stringify(this.name) + "] = fn(modules);\n" + | 
					
						
							|  |  |  | 		"			else\n" + | 
					
						
							|  |  |  | 		"				root[" + JSON.stringify(this.name) + "] = fn(modules);\n" + | 
					
						
							|  |  |  | 		"		}\n" + | 
					
						
							|  |  |  | 		"	}\n" + | 
					
						
							| 
									
										
										
										
											2013-03-26 23:54:41 +08:00
										 |  |  | 		"})(this)\n", "webpackUniversalModuleDefinition"), source); | 
					
						
							| 
									
										
										
										
											2013-03-11 21:51:23 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | UmdMainTemplateDecorator.prototype.updateHash = function(hash) { | 
					
						
							|  |  |  | 	hash.update("umd"); | 
					
						
							| 
									
										
										
										
											2013-06-28 20:20:11 +08:00
										 |  |  | 	hash.update(this.name + ""); | 
					
						
							| 
									
										
										
										
											2013-03-11 21:51:23 +08:00
										 |  |  | 	this.mainTemplate.updateHash(hash); | 
					
						
							|  |  |  | }; |