mirror of https://github.com/webpack/webpack.git
				
				
				
			Merge pull request #3938 from carloscuatin/refactor-normal-module-replacement-plugin
refactor(es6) upgrade NormalModuleReplacementPlugin to ES6 class
This commit is contained in:
		
						commit
						8ccbee608e
					
				|  | @ -2,19 +2,21 @@ | |||
| 	MIT License http://www.opensource.org/licenses/mit-license.php
 | ||||
| 	Author Tobias Koppers @sokra | ||||
| */ | ||||
| "use strict"; | ||||
| 
 | ||||
| var path = require("path"); | ||||
| const path = require("path"); | ||||
| 
 | ||||
| function NormalModuleReplacementPlugin(resourceRegExp, newResource) { | ||||
| class NormalModuleReplacementPlugin { | ||||
| 	constructor(resourceRegExp, newResource) { | ||||
| 		this.resourceRegExp = resourceRegExp; | ||||
| 		this.newResource = newResource; | ||||
| 	} | ||||
| module.exports = NormalModuleReplacementPlugin; | ||||
| NormalModuleReplacementPlugin.prototype.apply = function(compiler) { | ||||
| 	var resourceRegExp = this.resourceRegExp; | ||||
| 	var newResource = this.newResource; | ||||
| 	compiler.plugin("normal-module-factory", function(nmf) { | ||||
| 		nmf.plugin("before-resolve", function(result, callback) { | ||||
| 
 | ||||
| 	apply(compiler) { | ||||
| 		let resourceRegExp = this.resourceRegExp; | ||||
| 		let newResource = this.newResource; | ||||
| 		compiler.plugin("normal-module-factory", (nmf) => { | ||||
| 			nmf.plugin("before-resolve", (result, callback) => { | ||||
| 				if(!result) return callback(); | ||||
| 				if(resourceRegExp.test(result.request)) { | ||||
| 					if(typeof newResource === "function") { | ||||
|  | @ -25,7 +27,7 @@ NormalModuleReplacementPlugin.prototype.apply = function(compiler) { | |||
| 				} | ||||
| 				return callback(null, result); | ||||
| 			}); | ||||
| 		nmf.plugin("after-resolve", function(result, callback) { | ||||
| 			nmf.plugin("after-resolve", (result, callback) => { | ||||
| 				if(!result) return callback(); | ||||
| 				if(resourceRegExp.test(result.resource)) { | ||||
| 					if(typeof newResource === "function") { | ||||
|  | @ -37,4 +39,7 @@ NormalModuleReplacementPlugin.prototype.apply = function(compiler) { | |||
| 				return callback(null, result); | ||||
| 			}); | ||||
| 		}); | ||||
| }; | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| module.exports = NormalModuleReplacementPlugin; | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue