Skip to content

Commit 5adfabb

Browse files
committed
added replacement plugins
1 parent 001fd4f commit 5adfabb

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

lib/ContextReplacementPlugin.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
MIT License http://www.opensource.org/licenses/mit-license.php
3+
Author Tobias Koppers @sokra
4+
*/
5+
function ContextReplacementPlugin(resourceRegExp, newContentRegExp) {
6+
this.resourceRegExp = resourceRegExp;
7+
this.newContentRegExp = newContentRegExp
8+
}
9+
module.exports = ContextReplacementPlugin;
10+
ContextReplacementPlugin.prototype.apply = function(compiler) {
11+
var resourceRegExp = this.resourceRegExp;
12+
var newContentRegExp = this.newContentRegExp;
13+
compiler.plugin("context-module-factory", function(cmf) {
14+
cmf.plugin("after-resolve", function(result, callback) {
15+
if(resourceRegExp.test(result.resource)) {
16+
result.regExp = newContentRegExp;
17+
}
18+
return callback(null, result);
19+
});
20+
});
21+
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
MIT License http://www.opensource.org/licenses/mit-license.php
3+
Author Tobias Koppers @sokra
4+
*/
5+
function NormalModuleReplacementPlugin(resourceRegExp, newResource) {
6+
this.resourceRegExp = resourceRegExp;
7+
this.newResource = newResource
8+
}
9+
module.exports = NormalModuleReplacementPlugin;
10+
NormalModuleReplacementPlugin.prototype.apply = function(compiler) {
11+
var resourceRegExp = this.resourceRegExp;
12+
var newResource = this.newResource;
13+
compiler.plugin("normal-module-factory", function(nmf) {
14+
nmf.plugin("after-resolve", function(result, callback) {
15+
if(resourceRegExp.test(result.resource)) {
16+
result.resource = newResource;
17+
}
18+
return callback(null, result);
19+
});
20+
});
21+
};

0 commit comments

Comments
 (0)