workers-sdk
workers-sdk copied to clipboard
feat: `--env` + `.env`/`.dev.vars` (environment support for build/runtime vars)
trafficstars
We currently support dotenv integration in 2 ways -
- When you make a
.envfile in your project, any values in there are available onprocess.envduring custom builds. Further, you can even use this to populate values likeCLOUDFLARE_ACCOUNT_ID,CLOUDFLARE_API_TOKEN, etc. - When you make a file called
.dev.vars, we populate[vars]in runtime of the Worker, i.e. when the Worker is actually running. This is useful for swapping in vars during development without having to editwrangler.toml, but it's particularly useful when we need to populate secrets in local mode (since it wouldn't otherwise get the values we've set in the dashboard.
Neither of these files is meant to be checked in, and the .gitignore we generate during wrangler init includes them.
This issue is about expanding support, specifically about adding environment support. When using --env <environment>
- We should load
.env.<environment>when available (and use.envwhen it isn't). imo we should not merge values of both files, but I'm not sure what the norm is here and we should probably do that. - Similarly for runtime, we should load
.dev.vars.<environment>when available (and use.dev.varswhen it isn't).