Environment Variables - antonybudianto/angular-webpack-starter GitHub Wiki
As a developer who works with many environments, like local machine, your teammate's machine, staging, QA, or production, you need to make sure that changing app's config won't breaks other environments. The usual way is to have environment variables which varies between environments.
It's one of The Twelve-Factor App and I tried to adapt it as much as possible since some aren't applicable for client-side app.
The usual use cases:
- Staging server uses
stag-api.domain.comwhere Production server usesapi.domain.com - My local machine uses
localhostwhere my teammate's machine usesapi.domain.dev - PORT differences
The starter supports dotenv environment variables
It works by reading your .env located at project root and send it to process.env which Webpack will process
- Independently managed by each environment, resulting Scalable environment config (No file that groups every environments)
- No env is committed to source control
-
Create
.envfile or Copy one from.env.example - Access the variable from
process.env.<YOUR_VAR>on your node or app code
- Since this is client-side environment variables, DON'T STORE SENSITIVE INFORMATION like your api tokens, secret keys, or other variables that should be kept secret on server-side
- The whole Environment Variable is also optional, you can just ignore to create
.env