|
2 | 2 | MIT License http://www.opensource.org/licenses/mit-license.php |
3 | 3 | Author Tobias Koppers @sokra |
4 | 4 | */ |
5 | | -function ContextReplacementPlugin(resourceRegExp, newContentRegExp) { |
| 5 | +function ContextReplacementPlugin(resourceRegExp, newContentResource, newContentRecursive, newContentRegExp) { |
6 | 6 | this.resourceRegExp = resourceRegExp; |
7 | | - this.newContentRegExp = newContentRegExp |
| 7 | + if(typeof newContentResource !== "string") { |
| 8 | + newContentRegExp = newContentRecursive; |
| 9 | + newContentRecursive = newContentResource; |
| 10 | + newContentResource = undefined; |
| 11 | + } |
| 12 | + if(typeof newContentRecursive !== "boolean") { |
| 13 | + newContentRegExp = newContentRecursive; |
| 14 | + newContentRecursive = undefined; |
| 15 | + } |
| 16 | + this.newContentResource = newContentResource; |
| 17 | + this.newContentRecursive = newContentRecursive; |
| 18 | + this.newContentRegExp = newContentRegExp; |
8 | 19 | } |
9 | 20 | module.exports = ContextReplacementPlugin; |
10 | 21 | ContextReplacementPlugin.prototype.apply = function(compiler) { |
11 | 22 | var resourceRegExp = this.resourceRegExp; |
| 23 | + var newContentResource = this.newContentResource; |
| 24 | + var newContentRecursive = this.newContentRecursive; |
12 | 25 | var newContentRegExp = this.newContentRegExp; |
13 | 26 | compiler.plugin("context-module-factory", function(cmf) { |
14 | 27 | cmf.plugin("before-resolve", function(result, callback) { |
15 | 28 | if(!result) return callback(); |
16 | 29 | if(resourceRegExp.test(result.request)) { |
17 | | - result.regExp = newContentRegExp; |
| 30 | + if(typeof newContentResource !== "undefined") |
| 31 | + result.request = newContentResource; |
| 32 | + if(typeof newContentRecursive !== "undefined") |
| 33 | + result.recursive = newContentRecursive; |
| 34 | + if(typeof newContentRegExp !== "undefined") |
| 35 | + result.regExp = newContentRegExp; |
18 | 36 | } |
19 | 37 | return callback(null, result); |
20 | 38 | }); |
21 | 39 | cmf.plugin("after-resolve", function(result, callback) { |
22 | 40 | if(!result) return callback(); |
23 | 41 | if(resourceRegExp.test(result.resource)) { |
24 | | - result.regExp = newContentRegExp; |
| 42 | + if(typeof newContentResource !== "undefined") |
| 43 | + result.resource = newContentResource; |
| 44 | + if(typeof newContentRecursive !== "undefined") |
| 45 | + result.recursive = newContentRecursive; |
| 46 | + if(typeof newContentRegExp !== "undefined") |
| 47 | + result.regExp = newContentRegExp; |
25 | 48 | } |
26 | 49 | return callback(null, result); |
27 | 50 | }); |
|
0 commit comments