DEV Community

Discussion on: Stop using Dotenv in your front-end

Collapse
 
sbelzile profile image
Sébastien Belzile

Usually, in these cases, your bundler will output its results to a specific folder, ex: dist, www, out, etc.

The minimum you need is a command that takes a file from one place and copies it there:

cp config/prod.json dist/settings/environment.json
Enter fullscreen mode Exit fullscreen mode

Then, you can deploy the resulting folder.

Usually, in a CI/CD environment, you will want to set the content of these files to some CI/CD environment variables. In these cases, you may use something like envsubst or its node equivalent envsub.

Example of this (docker environment, files served by nginx)

entrypoint.sh:

#!/bin/sh
set -e

envsubst < /var/www/html/settings/settings.template.js > /var/www/html/settings/settings.js

exec nginx -g "daemon off;"
Enter fullscreen mode Exit fullscreen mode

Dockerfile:

[...]
COPY client/public/settings/settings.template.js usr/share/nginx/html/settings/settings.template.js
COPY client/config/entrypoint.sh /opt/entrypoint.sh
[...]
ENTRYPOINT ["sh", "/opt/entrypoint.sh"]
Enter fullscreen mode Exit fullscreen mode