Introduction
Laravel apps read sensitive information from their .env
file.
Recently I found out that Laravel Mix can pass values from the same .env
file to the js portion of your app as long as they are prefixed with MIX_
I use Gitlab ci pipelines to build production assets so that I dont need that additional tooling on the production servers the main one being:
yarn run production
This is preceded with cp .env.example .env
meaning when the build commands are being run, they are going to use values from the .example.env
file.
If your project doesn’t make use of anything from the .env
file then this is totally fine, however in scenarios where you do, since production applications will almost certainly have different .env
values to those in the .example.env
file (Never commit credentials to source control!) the resulting file will have been built with the wrong credentials.
In this article I’m going to show how you can use gitlab CI to build those assets with updated environmental variables so that they function as expected when deployed to your production servers.
Continue reading