Custom environment variables: unset variables cause unexpected minification
Created by: mfonsen
Can you reproduce the problem with latest npm?
yes (with latest yarn)
Description
If a custom environment variable is not set minification will not strip out dead code related to it.
This could cause unwanted development assets to go into the production build if the environment variables are not properly set.
If this is works as planned perhaps I could try to create a PR to mention this in the documentation.
Please consider the following example when running yarn run build
:
if (process.env.REACT_APP_FOO === 'bar') {
console.log('REACT_APP_FOO: bar')
} else {
console.log('REACT_APP_FOO: something else');
}
Expected behavior
string REACT_APP_FOO: bar
is not included in the bundle.
Actual behavior
REACT_APP_FOO: bar
is included in the bundle.
Environment
-
npm ls react-scripts
(if you haven’t ejected): └── react-scripts@0.9.4 -
node -v
: v6.10.0 -
npm -v
: 3.10.10 -
Operating system: macOS
-
Browser and version: Chrome 56.0.2924.87 (64-bit)
Reproducible Demo
Repo: https://github.com/mfonsen/create-react-app-undefined-env-vars Steps:
cd my-app
yarn
yarn run build
cat build/static/js/main.*.js | grep -Eo "REACT_APP_FOO: bar"
# returns REACT_APP_FOO: bar
REACT_APP_FOO="foobar" yarn run build
# does not return anything