Webpack cli arguments and parameters configuration within webpack.config.js

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.

Author: Fantashit

3 thoughts on “Webpack cli arguments and parameters configuration within webpack.config.js

  1. 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 my webpack.config.js file to write some kind of:

    debug: ! options.production

    And, because I use exclude to disable strip-loader in production mode, I want to use same option there. It is very useful to totally exclude my debug() function calls.

  2. 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 our webpack.config.js file. These are accessed via process.argv.

    For instance, webpack -d results in something like the following process.argv in my webpack.config.js:

    [
        '<local-path-here>/node',
        '<another-local-path-here>/webpack.js',
        '-d'
    ]
    

Comments are closed.