Webpack-cli: Enhance env flag support

Created on 12 Oct 2020  路  8Comments  路  Source: webpack/webpack-cli

Is your feature request related to a problem? Please describe.
env flag presently supports only booleans, which is not the most verbose thing to work with plus has high migration overhead as everyone is pretty much used to the old format. So we need to support at least custom string value for properties which are passed to env, something like -

webpack --env app="test" --env title="start"

Describe the solution you'd like

We'll have to introduce separate arg parsing behaviour for env.

Describe alternatives you've considered

Additional context

High enhancement

Most helpful comment

If you're looking for a quick snippet to get some env parsing back, you should be able to do something like:

env = Object.keys(env).reduce((acc, cur) => {
    const [key, value] = cur.split('=');
    acc[key] = value || env[key];
    return acc;
  }, {});

That should help to bring some of the key/value parsing back

webpack --env production --env app="test" --env title="start"
>>>
{
  production: true,
  app: 'test'
  title: 'start'
}

Hope that helps!

All 8 comments

Any chance of viewing this issue resolved anytime soon?

I think that should be reported on your docs (as a temporary fault on this version) as it can easily drive people nuts. It is also a huge regression (not enhancement as it's marked ATM) and it is against your own docs ( https://webpack.js.org/api/cli/#environment-options )

Please consider switch this issue type both for labels and work priority, for sake of a respectful community using your solution as a multi environment standard.

Any chance of viewing this issue resolved anytime soon?

No, it is OSS

Please consider switch this issue type both for labels and work priority, for sake of a respectful community using your solution as a multi environment standard.

You can help and send a PR

I could for sure, but i cannot change the labels nor webpack team priority neither i have the right skills to do a PR about it (i would happy to do it if i could!)

Anyway, as you avoid to reply to my comment section about it, I will then consider my thoughts accepted because hey... that's OSS spirt too :D

@LBRDan Because we have many issues, if you want this ASAP - send a PR

If you're looking for a quick snippet to get some env parsing back, you should be able to do something like:

env = Object.keys(env).reduce((acc, cur) => {
    const [key, value] = cur.split('=');
    acc[key] = value || env[key];
    return acc;
  }, {});

That should help to bring some of the key/value parsing back

webpack --env production --env app="test" --env title="start"
>>>
{
  production: true,
  app: 'test'
  title: 'start'
}

Hope that helps!

Thanks for all the input everyone, https://github.com/webpack/webpack-cli/pull/1939 should fix it and should land in the next release, hopefully soon :)

nps is executing default : nps webpack
nps is executing webpack : nps webpack.server
nps is executing webpack.server : webpack-dev-server -d --devtool '#source-map' --inline --env.server
[webpack-cli] Unknown argument: #source-map
[webpack-cli] Unknown argument: --inline
[webpack-cli] Unknown argument: --env.server
The script called "webpack.server" which runs "webpack-dev-server -d --devtool '#source-map' --inline --env.server" failed with exit code 2 https://github.com/sezna/nps/blob/master/other/ERRORS_AND_WARNINGS.md#failed-with-exit-code
The script called "webpack" which runs "nps webpack.server" failed with exit code 2 https://github.com/sezna/nps/blob/master/other/ERRORS_AND_WARNINGS.md#failed-with-exit-code
The script called "default" which runs "nps webpack" failed with exit code 2 https://github.com/sezna/nps/blob/master/other/ERRORS_AND_WARNINGS.md#failed-with-exit-code
npm ERR! code ELIFECYCLE
npm ERR! errno 2

How can I resolve above with below webpack packages:

"webpack": "^5.11.0",
"webpack-cli": "^4.2.0",
"webpack-dev-server": "^4.0.0-beta.0",

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fokusferit picture fokusferit  路  4Comments

logo749 picture logo749  路  4Comments

r00nscapenab picture r00nscapenab  路  4Comments

sam-s4s picture sam-s4s  路  5Comments

aleksandrlat picture aleksandrlat  路  3Comments