| 
									
										
										
										
											2014-08-25 15:50:26 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2017-01-09 02:11:26 +08:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2014-08-25 15:50:26 +08:00
										 |  |  | var ConstDependency = require("./dependencies/ConstDependency"); | 
					
						
							| 
									
										
										
										
											2017-01-09 02:11:26 +08:00
										 |  |  | const ParserHelpers = require("./ParserHelpers"); | 
					
						
							| 
									
										
										
										
											2014-08-25 15:50:26 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | var NullFactory = require("./NullFactory"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-13 06:20:09 +08:00
										 |  |  | function ExtendedAPIPlugin() {} | 
					
						
							| 
									
										
										
										
											2014-08-25 15:50:26 +08:00
										 |  |  | module.exports = ExtendedAPIPlugin; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var REPLACEMENTS = { | 
					
						
							| 
									
										
										
										
											2015-04-24 05:55:50 +08:00
										 |  |  | 	__webpack_hash__: "__webpack_require__.h" // eslint-disable-line camelcase
 | 
					
						
							| 
									
										
										
										
											2014-08-25 15:50:26 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | var REPLACEMENT_TYPES = { | 
					
						
							| 
									
										
										
										
											2015-04-24 05:55:50 +08:00
										 |  |  | 	__webpack_hash__: "string" // eslint-disable-line camelcase
 | 
					
						
							| 
									
										
										
										
											2014-08-25 15:50:26 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | ExtendedAPIPlugin.prototype.apply = function(compiler) { | 
					
						
							| 
									
										
										
										
											2016-09-14 18:04:42 +08:00
										 |  |  | 	compiler.plugin("compilation", function(compilation, params) { | 
					
						
							| 
									
										
										
										
											2014-08-25 15:50:26 +08:00
										 |  |  | 		compilation.dependencyFactories.set(ConstDependency, new NullFactory()); | 
					
						
							|  |  |  | 		compilation.dependencyTemplates.set(ConstDependency, new ConstDependency.Template()); | 
					
						
							|  |  |  | 		compilation.mainTemplate.plugin("require-extensions", function(source, chunk, hash) { | 
					
						
							|  |  |  | 			var buf = [source]; | 
					
						
							|  |  |  | 			buf.push(""); | 
					
						
							|  |  |  | 			buf.push("// __webpack_hash__"); | 
					
						
							|  |  |  | 			buf.push(this.requireFn + ".h = " + JSON.stringify(hash) + ";"); | 
					
						
							|  |  |  | 			return this.asString(buf); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 		compilation.mainTemplate.plugin("global-hash", function() { | 
					
						
							|  |  |  | 			return true; | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2016-09-14 18:04:42 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		params.normalModuleFactory.plugin("parser", function(parser, parserOptions) { | 
					
						
							|  |  |  | 			Object.keys(REPLACEMENTS).forEach(function(key) { | 
					
						
							| 
									
										
										
										
											2017-01-08 20:46:29 +08:00
										 |  |  | 				parser.plugin("expression " + key, ParserHelpers.toConstantDependency(REPLACEMENTS[key])); | 
					
						
							| 
									
										
										
										
											2017-01-09 02:11:26 +08:00
										 |  |  | 				parser.plugin("evaluate typeof " + key, ParserHelpers.evaluateToString(REPLACEMENT_TYPES[key])); | 
					
						
							| 
									
										
										
										
											2016-09-14 18:04:42 +08:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2014-08-25 15:50:26 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2015-07-08 20:39:02 +08:00
										 |  |  | }; |