Skip to content

Commit 48e17ab

Browse files
kinkasokra
authored andcommitted
support arguments input for CLI --plugin
using the parseQuery function of loader-utils, and get arguments for the plugin in the option --plugin. for example: `webpack --plugin DefinePlugin?{a:1,b:2}`
1 parent 6782a1e commit 48e17ab

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

bin/convert-argv.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,19 @@ module.exports = function(optimist, argv, convertOptions) {
193193
}
194194

195195
function loadPlugin(name) {
196+
var loadUtils = require("loader-utils");
197+
var args = null;
198+
try {
199+
var p = name && name.indexOf("?");
200+
if (p > -1) {
201+
args = loadUtils.parseQuery(name.substring(p));
202+
name = name.substring(0, p);
203+
}
204+
} catch(e) {
205+
console.log("Invalid plugin arguments" + e + ".");
206+
process.exit(-1);
207+
}
208+
196209
var path;
197210
try {
198211
path = resolve.sync(process.cwd(), name);
@@ -208,7 +221,7 @@ module.exports = function(optimist, argv, convertOptions) {
208221
throw e;
209222
}
210223
try {
211-
return new Plugin();
224+
return new Plugin(args);
212225
} catch(e) {
213226
console.log("Cannot instantiate plugin " + name + ". (" + path + ")");
214227
throw e;

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"js-beautify": "^1.5.10",
4242
"json-loader": "~0.5.1",
4343
"less-loader": "^2.0.0",
44+
"loader-utils": "^0.2.11",
4445
"mocha": "~2.2.0",
4546
"mocha-lcov-reporter": "0.0.2",
4647
"raw-loader": "~0.5.0",

0 commit comments

Comments
 (0)