mirror of https://github.com/webpack/webpack.git
Merge pull request #5346 from esbenp/rename-module-bind-config-keys-4917
rename --module-bind-x config keys from (pre/post)Loaders to rules
This commit is contained in:
commit
b409d9c8fa
|
@ -293,24 +293,30 @@ module.exports = function(yargs, argv, convertOptions) {
|
|||
ensureObject(options, "entry");
|
||||
});
|
||||
|
||||
function bindLoaders(arg, collection) {
|
||||
function bindRules(arg) {
|
||||
ifArgPair(arg, function(name, binding) {
|
||||
if(name === null) {
|
||||
name = binding;
|
||||
binding += "-loader";
|
||||
}
|
||||
options.module[collection].push({
|
||||
var rule = {
|
||||
test: new RegExp("\\." + name.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&") + "$"),
|
||||
loader: binding
|
||||
});
|
||||
};
|
||||
if(arg === "module-bind-pre") {
|
||||
rule.enforce = "pre";
|
||||
} else if(arg === "module-bind-post") {
|
||||
rule.enforce = "post";
|
||||
}
|
||||
options.module.rules.push(rule);
|
||||
}, function() {
|
||||
ensureObject(options, "module");
|
||||
ensureArray(options.module, collection);
|
||||
ensureArray(options.module, "rules");
|
||||
});
|
||||
}
|
||||
bindLoaders("module-bind", "loaders");
|
||||
bindLoaders("module-bind-pre", "preLoaders");
|
||||
bindLoaders("module-bind-post", "postLoaders");
|
||||
bindRules("module-bind");
|
||||
bindRules("module-bind-pre");
|
||||
bindRules("module-bind-post");
|
||||
|
||||
var defineObject;
|
||||
ifArgPair("define", function(name, value) {
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
post
|
|
@ -0,0 +1 @@
|
|||
pre
|
|
@ -0,0 +1,3 @@
|
|||
var pre = require('./file.pre');
|
||||
var post = require('./file.post');
|
||||
module.exports = "foo";
|
|
@ -0,0 +1,4 @@
|
|||
module.exports = function(source) {
|
||||
console.log('post-loaded ' + source.replace('\n', ''))
|
||||
return source;
|
||||
};
|
|
@ -0,0 +1,4 @@
|
|||
module.exports = function(source) {
|
||||
console.log('pre-loaded ' + source.replace('\n', ''))
|
||||
return source;
|
||||
};
|
|
@ -0,0 +1,10 @@
|
|||
"use strict";
|
||||
|
||||
module.exports = function testAssertions(code, stdout, stderr) {
|
||||
code.should.be.exactly(0);
|
||||
|
||||
stdout.should.be.ok();
|
||||
stdout.should.containEql("pre-loaded pre");
|
||||
stdout.should.containEql("post-loaded post");
|
||||
stderr.should.be.empty();
|
||||
};
|
|
@ -0,0 +1,7 @@
|
|||
--entry ./index.js
|
||||
--config ./webpack.config.js
|
||||
--output-filename [name].js
|
||||
--output-chunk-filename [id].chunk.js
|
||||
--target async-node
|
||||
--module-bind-pre pre=./pre-loader
|
||||
--module-bind-post post=./post-loader
|
|
@ -0,0 +1,5 @@
|
|||
var path = require("path");
|
||||
|
||||
module.exports = {
|
||||
entry: path.resolve(__dirname, "./index"),
|
||||
};
|
Loading…
Reference in New Issue