A Cli to generate runtime-env for frontend apps
npm install runtime-envRuntime-env is cli written in go to parse environment variables & generate a javascript file which adds these to the browsers window object.




``bash`
curl -sfL https://shkreios.github.io/runtime-env/install.sh | sh
`bash`
npm install --dev-save runtime-env
`bash`
yarn add -D runtime-env
`
NAME:
runtime-env - runtime envs for SPAs
USAGE:
runtime-env [global options]
VERSION:
v1.3.0
AUTHOR:
Simon Hessel
GLOBAL OPTIONS:
--env-file value, -f value The .env file to be parsed
--schema-file value, --schema value A .env file which contains a list of envs to be parsed
--prefix value, -p value The env prefix to matched
--output value, -o value Output file path (default: "./env.js")
--type-declarations-file value, --dts value Output file path for the typescript declaration file
--global-key value, --key value Customize the key on which the envs will be set on window object (default: "__RUNTIME_CONFIG__")
--remove-prefix Remove the prefix from the env (default: false)
--no-envs Only read envs from file not from environment variables (default: false)
--disable-logs, --no-logs Disable logging output (default: false)
--watch, -w Watch .env file (default: false)
--help, -h show help (default: false)
--version, -v print the version (default: false)
COPYRIGHT:
Copyright © 2022 Simon Hessel
`
`sh`.env input file
TEST=Test
`sh`
$ runtime-env -f .env --no-envs
`js`
window.__RUNTIME_CONFIG__ = { TEST: "Test" };
`js`
console.log(window.__RUNTIME_CONFIG__.TEST);
`sh
#!/bin/sh
...
`dockerfile
...install runtime-env via install.sh script
RUN wget -O - https://shkreios.github.io/runtime-env/install.sh | shimportant to be set after install.sh as otherwise binary will placed under /app/bin/runtime-env
WORKDIR /app/Copy your entrypoint script
COPY entrypoint.sh entrypoint.sh...
#
ENTRYPOINT ["./entrypoint.sh"]
optionaly set command
CMD ["nginx"]
...
`In CI/CD
`shuse either wget, curl or whatevery you ci env supports
curl -sfL https://shkreios.github.io/runtime-env/install.sh | sh
wget -O - https://shkreios.github.io/runtime-env/install.sh | sh
runtime-env # your runtime-env flags here
`$3
#### Read from secrets
`yaml
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: shkreios/runtime-env-action@v1
with:
version: v1.1.0
prefix: RUN_ENV_
output: ./public/env.js
removePrefix: "true"
env:
RUN_ENV_EXAMPLE: ${{ secrets.EXAMPLE }}
``js
// resulting env.js in public folder
window.__RUNTIME_CONFIG__ = { EXAMPLE: "SECRET_VALUE" };
`Why go / Why should i use this package?
There many solutions similar to this package
react-env, runtime-env-cra or sh` scripts to name a few. They all fall in one of 2 categories:1. they are either dependent on a runtime/interpreter to be preinstalled like nodejs or python or
2. they are not platform-agnostic
Go supports building binaries for multiple platforms and arches, and the binary itself includes everything to be executed. Therefore, no matter if development with npm or in docker CI/CD you can expect it to be easily installed and as light as it can be.
As this tool will mostly be used in npm codebases where you expect everything, including a tool that generates runtime-envs, to be installed via npm/yarn it's the best option.