Using multiple .env files in Svelte/Sveltekit
Asked Answered
M

0

6

I am familiar with Vite's very easy .env setup where you can have .env, .env.production, etc. With Sveltekit's "new" private/public/dyanmic stuff, I am not sure how it works now. Currently I have a .env file with dev info but I would like to have

  1. .env.dev
  2. .env.integration
  3. .env.production

Or something like that. Although I cannot figure out how to get this to work with Sveltekit, or really even where to define the env. I am not 100% positive if it uses NODE_ENV to determine the environment either.

Merideth answered 12/6, 2023 at 20:43 Comment(3)
Don't do that. Dotenv's own FAQ discourages it. Rather than rebuilding the app for every environment it needs to run in, promote an artifact and configure at deploy or run time). I've written more about this here: blog.jonrshar.pe/2020/Sep/19/spa-config.html.Sarthe
As one possible solution, because environment files just set environment variables, you can simply do source .env.production, or similar UNIX command, before running node on a production server.Shelly
You could add a prefix to the file name, such as: PROD_XYZ for produciton and DEV_XYZ for developmentEvaleen

© 2022 - 2024 — McMap. All rights reserved.