Laravel deploy to production and mix variable in env file issue

Viewed 426

Hi I am pretty new to Dev Ops side of things. So I have a Laravel Vue app where I utilize APIs for some request. Both web app and APIs are on same server for now.

So in my local env file I have variable like

MIX_DEFAULT_API_URL=http://127.0.0.1:8000

but in production env I have production URL

Problem is every time I push to production the links are overriden and I have to run

npm run production to fix that

is there any solution to this or this is the way it is ?

1 Answers

To answer your question: Yes, you need to run it against the current .env as the variables are included in the output.

You could, however, make use of a Mix extension to specify which .env file to use. In your case, you would need to create a .env.production file and have it reference that by way of updating your production script in package.json to:

{
  "production": "NODE_ENV=production ENV_FILE=./.env.production ..."
}

(truncated for brevity)

Then, when running the build locally, MIX_DEFAULT_API_URL will be your production URL, or whatever you use in the production env.

Related