-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
40 lines (37 loc) · 1.12 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var RuleSet;
try {
// webpack 2
RuleSet = require('webpack/lib/RuleSet');
}
catch (e) {}
module.exports = ChildCompilerLoaderListWebpackPlugin;
function ChildCompilerLoaderListWebpackPlugin(options) {
this.options = options;
}
ChildCompilerLoaderListWebpackPlugin.prototype.apply = function(compiler) {
var _this = this;
compiler.plugin('compilation', function(compilation, params) {
// webpack 2
if (params.normalModuleFactory.ruleSet) {
if (_this.options.test.test(compilation.name)) {
if (_this.options.rules) {
params.normalModuleFactory.ruleSet = new RuleSet(_this.options.rules);
}
}
}
// webpack 1
else {
if (_this.options.test.test(compilation.name)) {
if (_this.options.preLoaders) {
params.normalModuleFactory.preLoaders.list = _this.options.preLoaders;
}
if (_this.options.loaders) {
params.normalModuleFactory.loaders.list = _this.options.loaders;
}
if (_this.options.postLoaders) {
params.normalModuleFactory.postLoaders.list = _this.options.postLoaders;
}
}
}
});
}