Skip to content

Commit

Permalink
rename --module-bind-x config keys from (pre/post)Loaders to rules
Browse files Browse the repository at this point in the history
will also add enfore:pre/post to the rule configuration

closes #4917
  • Loading branch information
esbenp committed Jul 23, 2017
1 parent 4874584 commit d211ffb
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 6 deletions.
18 changes: 12 additions & 6 deletions bin/convert-argv.js
Expand Up @@ -293,24 +293,30 @@ module.exports = function(yargs, argv, convertOptions) {
ensureObject(options, "entry");
});

function bindLoaders(arg, collection) {
function bindRules(arg, collection) {
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[collection].push(rule);
}, function() {
ensureObject(options, "module");
ensureArray(options.module, collection);
});
}
bindLoaders("module-bind", "loaders");
bindLoaders("module-bind-pre", "preLoaders");
bindLoaders("module-bind-post", "postLoaders");
bindRules("module-bind", "rules");
bindRules("module-bind-pre", "rules");
bindRules("module-bind-post", "rules");

var defineObject;
ifArgPair("define", function(name, value) {
Expand Down
1 change: 1 addition & 0 deletions test/binCases/module/module-bind/file.post
@@ -0,0 +1 @@
post
1 change: 1 addition & 0 deletions test/binCases/module/module-bind/file.pre
@@ -0,0 +1 @@
pre
3 changes: 3 additions & 0 deletions test/binCases/module/module-bind/index.js
@@ -0,0 +1,3 @@
var pre = require('./file.pre');
var post = require('./file.post');
module.exports = "foo";
4 changes: 4 additions & 0 deletions test/binCases/module/module-bind/post-loader.js
@@ -0,0 +1,4 @@
module.exports = function(source) {
console.log('post-loaded ' + source.replace('\n', ''))
return source;
};
4 changes: 4 additions & 0 deletions test/binCases/module/module-bind/pre-loader.js
@@ -0,0 +1,4 @@
module.exports = function(source) {
console.log('pre-loaded ' + source.replace('\n', ''))
return source;
};
10 changes: 10 additions & 0 deletions test/binCases/module/module-bind/test.js
@@ -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();
};
7 changes: 7 additions & 0 deletions test/binCases/module/module-bind/test.opts
@@ -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
5 changes: 5 additions & 0 deletions test/binCases/module/module-bind/webpack.config.js
@@ -0,0 +1,5 @@
var path = require("path");

module.exports = {
entry: path.resolve(__dirname, "./index"),
};

0 comments on commit d211ffb

Please sign in to comment.