Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to .env and .env.local and away from .env.example #9701

Closed
coyotte508 opened this issue Apr 18, 2023 · 1 comment
Closed

Move to .env and .env.local and away from .env.example #9701

coyotte508 opened this issue Apr 18, 2023 · 1 comment

Comments

@coyotte508
Copy link
Contributor

coyotte508 commented Apr 18, 2023

Describe the problem

I'm always frustrated when cloning a sveltekit project with an environment.

I need to manually create a .env file, so that the typescript errors from importing on $env/static/private go away. Eg cp .env.example .env.

Why can't I just pnpm install && pnpm dev after cloning 😬

Describe the proposed solution

From the way SvelteKit handles environment, it would make sense to change this in the starter template's .gitignore:

  • ignore .env.local and .env.*.local, that's where the secrets or custom configs will be
  • do not ignore .env or .env.{production,development,test} : commit .env to the project by default! It should only contain non-sensitive default values.

SvelteKit refers to how Vite handles env

The .env.*.local files overrides the .env files, and Vite recommend ignoring the local files but not the other.

So you can have:

  • The default values in .env (and empty strings eg SECRET= for secrets, so that TS is happy)
  • Select env variables .env.local: secrets & custom overrides

Alternatives considered

Change SvelteKit to load default env from .env.example to make TS happy, but it's a breaking change.

Here only the docs + starter template need to be changed.

Importance

would make my life easier

Additional Information

Original comment here: #2925 (comment)

@dummdidumm
Copy link
Member

The decision to ignore .env by default which many people also use for sensitive environment variables outweighs the minor inconvenience of having to copy over stuff from a .env.example file - therefore closing. You are of course free to adjust this for your own project and modify the .gitignore that create-svelte produces.

@dummdidumm dummdidumm closed this as not planned Won't fix, can't repro, duplicate, stale May 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants