--env foo="" is true instead of being "".
denis-migdal opened this issue · 5 comments
Describe the bug
--env foo="" is true instead of being "".
To Reproduce
- Call webpack with the option
--env foo=""
- In webpack.config.js foo is equal to true instead of "".
Expected behavior
Foo should be equal to "" instead of true.
Looking into it 👍
I was able to reproduce, I am working on a fix.
I think you will have to escape the character on the terminal with \
-
Can you try - webpack --env foo=\"\"
But then the value of foo would be "\"\"". i.e. a string "" instead of an empty string.
With one of the old version of webpack-cli, in my package.json I had something like :
build: "webpack .... --env DIR_PREFIX \"$DIR_PREFIX\" --env SRC "
That I could call : DIR_PREFIX="/"; npm run build target1,target2,target2"
.
With the new version it is written :
build: "webpack .... --env DIR_PREFIX=\"$DIR_PREFIX\" --env SRC=\\"
However, I have 2 issues :
- if DIR_PREFIX is not specified instead of having the environment variable equals to en empty string, it is equal to true.
- my SRC environment variable is prefixed by a space due to how the command
npm run
works.
I succeeded to easily find a workaround, but I think --env PARAM=""
and --env PARAM
should be different, the first giving an empty string, the second, true.
It would then enable to do :
env.PARAM = env.PARAM ?? defaut_param; // default value if env.PARAM not defined
env.PARAM = env.PARAM || defaut_param; // default value if env.PARAM not defined or is an empty string
env.PARAM = env.PARAM !== true || default_param; // default value if env.PARAM is defined but with no values specified.
Yep bug