I wanted to have some additional control from within the webpack.config.js and preset some of the command line options as well as options that are not exposed inside the config.
Is it possible to have the options object passed to the configuration object and override the cli/defaults?
Seems the options are set in 2 files from what I examined bin/convert-argv.js and bin/webpack.js. For example I didn’t want to exclude all the default modules from the compilation listing and yet have the array elements customized so I added a function in my config like this:
var argsOutput = function(outputOptions) {
outputOptions.exclude = ['node_modules', 'jam', 'components'];
outputOptions.errorDetails = true;
};
Then I call it from webpack.js and have some of the output options preset.
You want a
stats
option in thewebpack.config.js
.I want type
webpack
to make my usual development builds.I want type
webpack -p
to build production config.I want use that
-p
flag within mywebpack.config.js
file to write some kind of:And, because I use
exclude
to disablestrip-loader
in production mode, I want to use same option there. It is very useful to totally exclude mydebug()
function calls.An effective workaround is to use node’s
process.argv
. Webpack passes its cli arguments to node, to which we then have access to in ourwebpack.config.js
file. These are accessed viaprocess.argv
.For instance,
webpack -d
results in something like the followingprocess.argv
in mywebpack.config.js
: