The .env.Production variable is undefined after Vue is built
P粉897881626
2023-08-29 17:52:12
<p>I have two <code>.env</code> files in my Vue 2.2.3 project, <code>.env.development</code> and <code>.env.development</ code>. </p>
<p>In each <code>.env</code> file, I have assigned the <code>VUE_APP_API_URL</code> variable to a different value - one for my local development environment and another For use on production servers. </p>
<p>Running <code>npm run build</code> compiles the application into the local <code>dist</code> folder without any problems. However, logging <code>VUE_APP_API_URL</code> in my Vue application returns <code>undefined</code> when I deploy <code>dist</code> to my server. </p>
<p>This is my first time doing this, so I might be missing something. Is there anything else I have to do in order for the <code>.env.production</code> URL to work with the build? </p>
<p>Thanks in advance for your help! </p>
My advice is: don’t overcomplicate it. Just use a .env file.
Please make sure not to push it to the repository or it will be made public. That's all.
My configuration is: .env for dev, which contains constants.
Then in production you just set the variable there.