feat: Vite environment API
closes https://github.com/sveltejs/kit/issues/13692 closes https://github.com/sveltejs/kit/issues/1712 part of https://github.com/sveltejs/kit/issues/3535 closes https://github.com/sveltejs/kit/pull/13739 closes https://github.com/sveltejs/kit/pull/13357 closes https://github.com/sveltejs/kit/pull/12637
w.i.p and still has a lot of problems to solve. Needed to open this PR to test installing this from pkg.pr.new since linking locally with pnpm symlinks to the local kit repo. Then, when we try importing kit code from inside an environment, it results in a path which doesn't exist such as /packages/kit/.... Instead, it should probably import from node_modules/@sveltejs/kit/....
This PR adopts the Vite Environment API in kit and changes adapter-cloudflare to use a similar approach to Remix where the user can specify their own worker.js file. Otherwise, we can generate the wrangler config and worker for them. This approach integrates well with vite-plugin-cloudflare and provides users with direct access to the worker script, allowing them to export Durable Objects and add additional handlers.
Thanks to @jamesopstad for https://github.com/sveltejs/kit/pull/12637 and writing up the Google Doc explaining the Remix and vite-plugin-cloudflare integration. Resources include:
- https://vite.dev/guide/api-environment.html
- https://github.com/cloudflare/workers-sdk/tree/main/packages/vite-plugin-cloudflare
- https://github.com/remix-run/react-router/tree/main/playground/vite-plugin-cloudflare
TODO
- [ ] Cloudflare dev
- [ ] Cloudflare build
- [ ] Node
- [ ] vite-plugin-netlify
- [ ] Vercel?
- [ ] SPA/static?
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
- [x] It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
- [ ] This message body should clearly illustrate what problems it solves.
- [ ] Ideally, include a test that fails without this PR but passes with it.
Tests
- [ ] Run the tests with
pnpm testand lint the project withpnpm lintandpnpm check
Changesets
- [ ] If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running
pnpm changesetand following the prompts. Changesets that add features should beminorand those that fix bugs should bepatch. Please prefix changeset messages withfeat:,fix:, orchore:.
Edits
- [x] Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.