fix: restart Vite if tutorial has a .env file #207
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fixes #206
There are two problems with #206.
For the first problem, as expected, learn.svelte.dev waits for Vite dev server to restart when a
.dev
file is also added, but Vite only restarts when the.env
file is changed.https://github.com/vitejs/vite/blob/d953536aae448e2bea0f3a7cb3c0062b16d45597/packages/vite/src/node/server/index.ts#L486-L503
https://github.com/vitejs/vite/blob/d953536aae448e2bea0f3a7cb3c0062b16d45597/packages/vite/src/node/server/hmr.ts#L54-L72
learn.svelte.dev/src/lib/client/adapters/webcontainer/index.js
Lines 235 to 243 in 1c3bebf
So, you might assume that just make learn.svelte.dev not wait for Vite dev server to restart when a
.env
file is added, but that would not solve the second problem.As for the second problem, it is due to Vite's behavior. That is, when a
.env
file is added, the Vite dev server must be restarted in order to make the environment variables loaded from the.env
file available.In other words, if switching to a tutorial with a
. env
file, the Vite dev server must be restarted. However, I looked through the Vite documentation and could not find a way to restart Vite.This PR fix is hacky, but it solves both problems. Of course, if you have a better idea, I would like to do so.