stack-env

flexiable configuring env

Usage no npm install needed!

<script type="module">
  import stackEnv from 'https://cdn.skypack.dev/stack-env';
</script>

README

stack-env

NPM

npm package NPM downloads Average time to resolve an issue

What problem it tries to resolve

create-react-app provides the basic mechanism to differentiate development and production env, but it lacks the capability of dividing multiple 'production' env. Let's say there are qa, stg, prod, three stacks, we are not able to give different env variables per stack like Spring-Profile. Here I want to introduce stack-env which means to resolve this pain point.

Get started

The major concept in stack-env is stack and corresponding env files. e.g., stacks: qa, stg, prod, files: senv.qa, senv.stg, senv.prod

When stack-env runs, it read the stack from process.env to recognize what the exact stack it runs on. And then read the corresponding env file and load it as the env variables. In the end, the desired command runs in an env that all env variables come from the env file.

Usage

  Usage: senv [options] [command]
  
  Commands:
    help     Display help
    version  Display version
  
  Options:
    -c, --cmd      The command to run
    -f, --file     Choose an env file
    -h, --help     Output usage information
    -k, --key      Stack key
    -v, --verbose  Print full logs
    -V, --version  Output the version number

e.g. load env and run command yarn build.

senv -c 'yarn build'

Alias

What if the injected stack key is not 'stack' but others. stack-env provides a simple configuration section which is located in package.json to give an alias of the key.

"senv": {
  "key": "any-key"
}

Or through the cmd.

stack-env -k 'any-key' -c 'other commands'

LICENSE

MIT