Home  >  Q&A  >  body text

The .env.Production variable is undefined after Vue is built

<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>
P粉897881626P粉897881626416 days ago438

reply all(1)I'll reply

  • P粉348915572

    P粉3489155722023-08-30 11:29:20

    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.

    reply
    0
  • Cancelreply