mirror of https://github.com/webpack/webpack.git
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}`
This commit is contained in:
parent
6782a1e2bb
commit
48e17ab308
|
@ -193,6 +193,19 @@ module.exports = function(optimist, argv, convertOptions) {
|
|||
}
|
||||
|
||||
function loadPlugin(name) {
|
||||
var loadUtils = require("loader-utils");
|
||||
var args = null;
|
||||
try {
|
||||
var p = name && name.indexOf("?");
|
||||
if (p > -1) {
|
||||
args = loadUtils.parseQuery(name.substring(p));
|
||||
name = name.substring(0, p);
|
||||
}
|
||||
} catch(e) {
|
||||
console.log("Invalid plugin arguments" + e + ".");
|
||||
process.exit(-1);
|
||||
}
|
||||
|
||||
var path;
|
||||
try {
|
||||
path = resolve.sync(process.cwd(), name);
|
||||
|
@ -208,7 +221,7 @@ module.exports = function(optimist, argv, convertOptions) {
|
|||
throw e;
|
||||
}
|
||||
try {
|
||||
return new Plugin();
|
||||
return new Plugin(args);
|
||||
} catch(e) {
|
||||
console.log("Cannot instantiate plugin " + name + ". (" + path + ")");
|
||||
throw e;
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
"js-beautify": "^1.5.10",
|
||||
"json-loader": "~0.5.1",
|
||||
"less-loader": "^2.0.0",
|
||||
"loader-utils": "^0.2.11",
|
||||
"mocha": "~2.2.0",
|
||||
"mocha-lcov-reporter": "0.0.2",
|
||||
"raw-loader": "~0.5.0",
|
||||
|
|
Loading…
Reference in New Issue