| 
									
										
										
										
											2014-08-25 15:50:26 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | var ConstDependency = require("./dependencies/ConstDependency"); | 
					
						
							|  |  |  | var BasicEvaluatedExpression = require("./BasicEvaluatedExpression"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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) { | 
					
						
							|  |  |  | 				parser.plugin("expression " + key, function(expr) { | 
					
						
							|  |  |  | 					var dep = new ConstDependency(REPLACEMENTS[key], expr.range); | 
					
						
							|  |  |  | 					dep.loc = expr.loc; | 
					
						
							|  |  |  | 					this.state.current.addDependency(dep); | 
					
						
							|  |  |  | 					return true; | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 				parser.plugin("evaluate typeof " + key, function(expr) { | 
					
						
							|  |  |  | 					return new BasicEvaluatedExpression().setString(REPLACEMENT_TYPES[key]).setRange(expr.range); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2014-08-25 15:50:26 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2015-07-08 20:39:02 +08:00
										 |  |  | }; |