Open dobromir-hristov opened 2 years ago
I met the same issue, and it is only found in Single File Component. If I use const IS_FOO = process.env.isFoo;
in js file, the value is replaced with string value during build time. If I use const IS_FOO = process.env.isFoo;
in *.vue file, the entire process.env object gets bundled.
With @vue/cli-service@4.5.15, there is no problem with usage like const IS_FOO = process.env.isFoo;
. The variable will be replaced with the text string at build time. So I think a best practice is never using the entire process.env
object in the code. I don't think anyone want embed the entire process.env into the code.
Version
4.5.15
Reproduction link
github.com
Environment info
Steps to reproduce
run the
build
command. Observe thedist/app.js
file and search forisFoo
.What is expected?
Accessing undefined properties in the
env
object to be replaced withundefined
, so the minify plugin can clean up and delete code blocks.What is actually happening?
The entire env object gets injected, everywhere you use the
process.env
object.gets roughly transformed to
I realise this is probably not Vue/CLI fault and is strictly a webpack thing, but I thought I may be doing something wrong. I looked all over and I could not find a similar issue.