Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v4-beta : use env variable with config as a function #1689

Closed
xylolink opened this issue Jul 17, 2020 · 19 comments
Closed

v4-beta : use env variable with config as a function #1689

xylolink opened this issue Jul 17, 2020 · 19 comments

Comments

@xylolink
Copy link

Describe the bug

We need to manipulate env vars in the config file to adjust the compilation entries points

What is the current behavior?
Cli does not recognize --env.MYVAR parameter
Config returning this kind of result is not considered by CLI without any error message :
module.exports = (env) => { return { // my conf }

To Reproduce

encapsulate your config object in a function and try to compile it.

Expected behavior

CLI should receive config functions and --env parameters

Screenshots

Compilation results without function
image

Compilation result with function
image

Unknown --env params
image

@snitin315
Copy link
Member

In starting we dropped the support of --env but as per feedback of users, We have added back the support of --env in 7249153 .
Maybe you should try it once again with webpack-cli next branch

@xylolink
Copy link
Author

Ok thanks !

I tried to update my npm. with npm install --save-dev git://github.com/webpack/webpack-cli.git#next webpack@next

Here's my package.json update :
{ "webpack-cli": "^4.0.0-beta.8", "webpack-cli-monorepo": "git://github.com/webpack/webpack-cli.git#next", }

But cli still does not recognize --env.VAR
image

Any idea why npm is not taking the last version ?

@snitin315
Copy link
Member

I think we support it like --env <development | production | none>, and not like the old cli.
/cc @anshumanv

@anshumanv
Copy link
Member

I tried to update my npm. with npm install --save-dev git://github.com/webpack/webpack-cli.git#next webpack@next

Hey @xylolink 👋

The env flag presently only supports string in the format --env TEST, are there use cases when you need a object?

@xylolink
Copy link
Author

xylolink commented Jul 17, 2020

--env params is also unknown

image

And yes, i need multiple env vars management to customize entry points from my dockerfile.

@anshumanv
Copy link
Member

Unusual, seems to be working for me

image

@xylolink
Copy link
Author

Maybe the problem is that I retrieve webpack-cli-monorepo from github ?

@anshumanv
Copy link
Member

Yes, seems so. Can you try to update your package.json like this and try reinstalling?

"webpack-cli": "git://github.com/webpack/webpack-cli.git#next"

@anshumanv
Copy link
Member

anshumanv commented Jul 31, 2020

@xylolink added support for multiple env in #1715

But the syntax is slightly different because we're using a different parser now,

webpack-cli --env test-version --env test-cli which will make the env param as

{ test-version: true, test-cli: true} so you can destructure these things from your env param and use to structure your config, is that something you can work with?

/cc @evilebottnawi

@snitin315
Copy link
Member

@anshumanv with commander 6 now we can support --env test-version test-cli => { test-version: true, test-cli: true}.

Should I create a PR for the same?
Reference https://github.com/tj/commander.js/#variadic-option

@rishabh3112
Copy link
Member

rishabh3112 commented Jul 31, 2020

we can support --env test-version test-cli => { test-version: true, test-cli: true}.

+1 from my side on this.

@anshumanv
Copy link
Member

@anshumanv with commander 6 now we can support --env test-version test-cli => { test-version: true, test-cli: true}.

yep that will be good, go ahead 👍

@alexander-akait
Copy link
Member

@anshumanv webpack-cli --env test-version --env test-cli is right syntax, using --env test-version test-cli is misleading can be create potential problems like --env test-version ./src/index.js

@snitin315
Copy link
Member

@anshumanv webpack-cli --env test-version --env test-cli is right syntax, using --env test-version test-cli is misleading can be create potential problems like --env test-version ./src/index.js

It can cause trouble in this case but might be handy for cases when we have long flag name like, weback-cli --resolve-alias-alias alias1 alias2 --resolve-alias-name name1 name2

@alexander-akait
Copy link
Member

For complex cases you should use webpack.config.js, no need to support misleading behavior weback-cli --resolve-alias-alias alias1 alias2 can be weback-cli --resolve-alias-alias index.js main.js and you can never understand what the developer meant

@snitin315
Copy link
Member

Agreed.

@anshumanv
Copy link
Member

Should we close this?

@alexander-akait
Copy link
Member

I think yes, we fix it

@anshumanv
Copy link
Member

Closing, feel free to open a new issue for any feedback/problems. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants