Custom command line arguments fail in webpack 2

Prior to webpack 2 I was able to parse custom command line options in the webpack config file. With webpack 2 any unknown option causes the build to fail most likely because yargs is executed in strict mode.

The use case here is for passing in arguments to be parsed in the config file before starting webpack. We do this to provide users the ability to perform custom builds by including/excluding modules or groups of modules. For example:

npm run dev -- --include player_flash,ads

I don’t recall this being a supported feature in webpack 1 but is there any reason why it shouldn’t be? Is there a better way of doing this?

Author: Fantashit

1 thought on “Custom command line arguments fail in webpack 2

  1. do this instead:

    // webpack.config.js
    module.exports = function(env) {
      // do something with env
      // i. e. read env.include
      return {
        entry: "...",
        devtool: env.devtool
      };
    }
    npm run dev -- --env.include player_flash,ads
    

    --env is for custom arguments. And it’s passed as argument to the function exported as configuration.

Comments are closed.