| 
									
										
										
										
											2014-03-05 16:58:51 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | var Module = require("./Module"); | 
					
						
							|  |  |  | var OriginalSource = require("webpack-core/lib/OriginalSource"); | 
					
						
							|  |  |  | var RawSource = require("webpack-core/lib/RawSource"); | 
					
						
							| 
									
										
										
										
											2014-07-03 06:00:06 +08:00
										 |  |  | var WebpackMissingModule = require("./dependencies/WebpackMissingModule"); | 
					
						
							| 
									
										
										
										
											2014-03-05 16:58:51 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | function ExternalModule(request, type) { | 
					
						
							|  |  |  | 	Module.call(this); | 
					
						
							|  |  |  | 	this.request = request; | 
					
						
							|  |  |  | 	this.type = type; | 
					
						
							|  |  |  | 	this.built = false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | module.exports = ExternalModule; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ExternalModule.prototype = Object.create(Module.prototype); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ExternalModule.prototype.external = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ExternalModule.prototype.identifier = function() { | 
					
						
							| 
									
										
										
										
											2014-03-06 02:55:53 +08:00
										 |  |  | 	return "external " + JSON.stringify(this.request); | 
					
						
							| 
									
										
										
										
											2014-03-05 16:58:51 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ExternalModule.prototype.readableIdentifier = function(requestShortener) { | 
					
						
							| 
									
										
										
										
											2014-03-06 02:55:53 +08:00
										 |  |  | 	return "external " + JSON.stringify(this.request); | 
					
						
							| 
									
										
										
										
											2014-03-05 16:58:51 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ExternalModule.prototype.needRebuild = function(fileTimestamps, contextTimestamps) { | 
					
						
							|  |  |  | 	return false; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ExternalModule.prototype.build = function(options, compilation, resolver, fs, callback) { | 
					
						
							|  |  |  | 	this.builtTime = new Date().getTime(); | 
					
						
							|  |  |  | 	callback(); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ExternalModule.prototype.source = function(dependencyTemplates, outputOptions, requestShortener) { | 
					
						
							|  |  |  | 	var str = "throw new Error('Externals not supported');"; | 
					
						
							|  |  |  | 	var request = this.request; | 
					
						
							| 
									
										
										
										
											2014-03-06 02:55:53 +08:00
										 |  |  | 	if(typeof request === "object") request = request[this.type]; | 
					
						
							| 
									
										
										
										
											2014-03-05 16:58:51 +08:00
										 |  |  | 	switch(this.type) { | 
					
						
							|  |  |  | 	case "this": | 
					
						
							| 
									
										
										
										
											2014-04-06 00:10:47 +08:00
										 |  |  | 	case "window": | 
					
						
							|  |  |  | 	case "global": | 
					
						
							| 
									
										
										
										
											2014-03-06 02:55:53 +08:00
										 |  |  | 		if(Array.isArray(request)) { | 
					
						
							| 
									
										
										
										
											2014-04-06 00:10:47 +08:00
										 |  |  | 			str = "(function() { module.exports = " + this.type + request.map(function(r) { | 
					
						
							| 
									
										
										
										
											2014-03-06 02:55:53 +08:00
										 |  |  | 				return "[" + JSON.stringify(r) + "]"; | 
					
						
							|  |  |  | 			}).join("") + "; }());"; | 
					
						
							|  |  |  | 		} else | 
					
						
							| 
									
										
										
										
											2014-04-06 00:10:47 +08:00
										 |  |  | 			str = "(function() { module.exports = " + this.type + "[" + JSON.stringify(request) + "]; }());"; | 
					
						
							| 
									
										
										
										
											2014-03-05 16:58:51 +08:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case "commonjs": | 
					
						
							|  |  |  | 	case "commonjs2": | 
					
						
							|  |  |  | 		if(Array.isArray(request)) { | 
					
						
							|  |  |  | 			str = "module.exports = require(" + JSON.stringify(request[0]) + ")" + request.slice(1).map(function(r) { | 
					
						
							|  |  |  | 				return "[" + JSON.stringify(r) + "]"; | 
					
						
							|  |  |  | 			}).join("") + ";"; | 
					
						
							| 
									
										
										
										
											2014-07-22 23:10:15 +08:00
										 |  |  | 		} else | 
					
						
							| 
									
										
										
										
											2014-03-05 16:58:51 +08:00
										 |  |  | 			str = "module.exports = require(" + JSON.stringify(request) + ");"; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case "amd": | 
					
						
							|  |  |  | 	case "umd": | 
					
						
							| 
									
										
										
										
											2014-07-22 23:10:15 +08:00
										 |  |  | 	case "umd2": | 
					
						
							| 
									
										
										
										
											2014-07-03 06:00:06 +08:00
										 |  |  | 		str = ""; | 
					
						
							|  |  |  | 		if(this.optional) { | 
					
						
							|  |  |  | 			str += "if(typeof __WEBPACK_EXTERNAL_MODULE_" + this.id + "__ === 'undefined') {" + WebpackMissingModule.moduleCode(request) + "}\n"; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		str += "module.exports = __WEBPACK_EXTERNAL_MODULE_" + this.id + "__;"; | 
					
						
							| 
									
										
										
										
											2014-03-05 16:58:51 +08:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2014-04-17 14:58:12 +08:00
										 |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2014-07-03 06:00:06 +08:00
										 |  |  | 		str = ""; | 
					
						
							|  |  |  | 		if(this.optional) { | 
					
						
							|  |  |  | 			str += "if(typeof " + request + " === 'undefined') {" + WebpackMissingModule.moduleCode(request) + "}\n"; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		str += "module.exports = " + request + ";"; | 
					
						
							| 
									
										
										
										
											2014-04-17 14:58:12 +08:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2014-03-05 16:58:51 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	if(this.useSourceMap) { | 
					
						
							|  |  |  | 		return new OriginalSource(str, this.identifier()); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		return new RawSource(str); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ExternalModule.prototype.size = function() { | 
					
						
							|  |  |  | 	return 42; | 
					
						
							| 
									
										
										
										
											2014-07-22 23:10:15 +08:00
										 |  |  | }; |