parallel-webpack icon indicating copy to clipboard operation
parallel-webpack copied to clipboard

Support argv as second config param

Open HaNdTriX opened this issue 6 years ago • 8 comments

Explain the problem

Sometimes a developer wants to access webpacks internal command line options in his config.

Expected Behaviour

The config function should pass two params into the config function:

  • An environment as the first parameter. See the environment options CLI documentation for syntax examples.
  • An options map (argv) as the second parameter. This describes the options passed to webpack, with keys such as output-filename and optimize-minimize.

source

Actual Behaviour

parallel-webpack omits the second param (argv).

Provide your webpack config

module.exports = (env, argv) => {
     console.log('isEnvSet', !!env)
     console.log('isArgvSet', !!argv)
     return {}
}

Steps to reproduce

Use the config above and run:

parallel-webpack --config=webpack.config.js

Provide your Environment details

  • Node version: v9.1.0
  • Operating System: MacOS 10.13.3
  • webpack version: 3.11.0
  • parallel-webpack version: 2.3.0

HaNdTriX avatar Feb 28 '18 14:02 HaNdTriX

closing for know, unit I got additional infos on the topic.

HaNdTriX avatar Feb 28 '18 15:02 HaNdTriX

This is also an issue for me. Webpack passes an object containing the argv (eg {mode: 'production'}) as 2nd argument to module.exports

mzealey avatar Jan 10 '19 08:01 mzealey

I also have the same issue - not able to access argv.mode when using like this:

module.exports = (env, argv) => {
}

@HaNdTriX are there any planms to fix it? As it is impossible to simply replace webpack with parallel-webpack in cli.

eugef avatar Jul 09 '19 09:07 eugef

@eugef I am not the author/contributor of this package.

Nevertheless, I reopen this issue for you guys. I am not using parallel-webpack anymore.

HaNdTriX avatar Jul 09 '19 16:07 HaNdTriX

Are you using smth else instead?

eugef avatar Jul 09 '19 16:07 eugef

Nope.

HaNdTriX avatar Jul 09 '19 18:07 HaNdTriX

I'm happy to merge a PR that adjusts this according to your needs.

pago avatar Jul 12 '19 17:07 pago

This also works:

package.json

"scripts": {
  "start": "parallel-webpack -- --foo=bar"
}

webpack.config.js

const parser = require('yargs').parse;

const parsedArgv = parser(process.argv);
console.log(parsedArgv.foo); // bar

iorrah avatar Jul 21 '20 10:07 iorrah