Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

chrisgrim's avatar

Defining a .env variable based on webpack environment?

Hi, In my .env file I have an image path for my project

MIX_IMAGE_URL=https://ei-test.sfo3.digitaloceanspaces.com/public/

Is there a way to setup webpack so that when I run npm run dev it uses

MIX_IMAGE_URL=https://ei-test.sfo3.digitaloceanspaces.com/public/

and then when I run npm run prod it uses

MIX_IMAGE_URL=https://ei-production.sfo3.digitaloceanspaces.com/public/
0 likes
3 replies
christian-qode's avatar

When you build for production (npm run prod) you should have a different (production) .env file, so I don't see the problem?

chrisgrim's avatar

Hi @christian-qode I have a separate env on my server that I have setup for production however in my local development folder I only have one .env file. Should I have two .env files in my local development folder?

Please or to participate in this conversation.