| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2017-01-03 01:00:08 +08:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-03 01:00:08 +08:00
										 |  |  | const ConstDependency = require("./dependencies/ConstDependency"); | 
					
						
							| 
									
										
										
										
											2017-01-09 02:11:26 +08:00
										 |  |  | const ParserHelpers = require("./ParserHelpers"); | 
					
						
							| 
									
										
										
										
											2014-06-16 21:18:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-03 01:00:08 +08:00
										 |  |  | const NullFactory = require("./NullFactory"); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-03 01:00:08 +08:00
										 |  |  | const REPLACEMENTS = { | 
					
						
							| 
									
										
										
										
											2015-06-01 05:28:24 +08:00
										 |  |  | 	__webpack_require__: "__webpack_require__", // eslint-disable-line camelcase
 | 
					
						
							| 
									
										
										
										
											2015-04-24 05:55:50 +08:00
										 |  |  | 	__webpack_public_path__: "__webpack_require__.p", // eslint-disable-line camelcase
 | 
					
						
							|  |  |  | 	__webpack_modules__: "__webpack_require__.m", // eslint-disable-line camelcase
 | 
					
						
							|  |  |  | 	__webpack_chunk_load__: "__webpack_require__.e", // eslint-disable-line camelcase
 | 
					
						
							|  |  |  | 	__non_webpack_require__: "require", // eslint-disable-line camelcase
 | 
					
						
							| 
									
										
										
										
											2016-08-30 02:49:11 +08:00
										 |  |  | 	__webpack_nonce__: "__webpack_require__.nc", // eslint-disable-line camelcase
 | 
					
						
							| 
									
										
										
										
											2015-06-13 17:45:28 +08:00
										 |  |  | 	"require.onError": "__webpack_require__.oe" // eslint-disable-line camelcase
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2017-01-03 01:00:08 +08:00
										 |  |  | const REPLACEMENT_TYPES = { | 
					
						
							| 
									
										
										
										
											2015-04-24 05:55:50 +08:00
										 |  |  | 	__webpack_public_path__: "string", // eslint-disable-line camelcase
 | 
					
						
							|  |  |  | 	__webpack_require__: "function", // eslint-disable-line camelcase
 | 
					
						
							|  |  |  | 	__webpack_modules__: "object", // eslint-disable-line camelcase
 | 
					
						
							| 
									
										
										
										
											2016-08-30 02:49:11 +08:00
										 |  |  | 	__webpack_chunk_load__: "function", // eslint-disable-line camelcase
 | 
					
						
							|  |  |  | 	__webpack_nonce__: "string" // eslint-disable-line camelcase
 | 
					
						
							| 
									
										
										
										
											2013-07-11 05:20:07 +08:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2017-01-03 01:00:08 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | const IGNORES = []; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class APIPlugin { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	apply(compiler) { | 
					
						
							|  |  |  | 		compiler.plugin("compilation", (compilation, params) => { | 
					
						
							|  |  |  | 			compilation.dependencyFactories.set(ConstDependency, new NullFactory()); | 
					
						
							|  |  |  | 			compilation.dependencyTemplates.set(ConstDependency, new ConstDependency.Template()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			params.normalModuleFactory.plugin("parser", parser => { | 
					
						
							|  |  |  | 				Object.keys(REPLACEMENTS).forEach(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
										 |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2017-01-03 01:00:08 +08:00
										 |  |  | 				IGNORES.forEach(key => { | 
					
						
							| 
									
										
										
										
											2017-01-11 20:11:42 +08:00
										 |  |  | 					parser.plugin(key, ParserHelpers.skipTraversal); | 
					
						
							| 
									
										
										
										
											2016-09-14 18:04:42 +08:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-01-03 01:00:08 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = APIPlugin; |