workers-sdk icon indicating copy to clipboard operation
workers-sdk copied to clipboard

feat: `--env` + `.env`/`.dev.vars` (environment support for build/runtime vars)

Open threepointone opened this issue 3 years ago • 0 comments
trafficstars

We currently support dotenv integration in 2 ways -

  • When you make a .env file in your project, any values in there are available on process.env during custom builds. Further, you can even use this to populate values like CLOUDFLARE_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 edit wrangler.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 .env when 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.vars when it isn't).

threepointone avatar Jun 20 '22 06:06 threepointone