bwrice's avatar
Level 11

How do you handle Mix ENV vars that are different per environment?

I have an app using Pusher that is separated into multiple environments, meaning the value for MIX_PUSHER_APP_KEY in my environment file is different per environment.

For a typical ENV var that gets pulled using PHP this would be fine, because your config will just read the specific value for that environment, but for MIX that value gets compiled into your assets when you run "npm dev", "npm prod" etc.

Right now, my only solution is to change the ENV value to the production value right before I run "npm prod" and then switching it back when I'm done pushing my changes to my repo.

Is there a way to instruct MIX to use different ENV vars based on the npm command? Or has anyone come across this problem and come up with a better solution?

0 likes
1 reply
fylzero's avatar

@bwrice You should really be running npm run prod in your deployment script or before deploying anyway. I would just add this command to Envoy, Forge or whatever you are using and automate that in your deployment process so you don't have to worry about it.

1 like

Please or to participate in this conversation.