feat(vite): auto-detect SvelteKit Cloudflare adapter#827
Merged
Conversation
Contributor
|
The changes in this PR will be included in the next version bump.
|
commit: |
f557e66 to
b6b090f
Compare
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
varlock-website | f9dcd3f | Commit Preview URL Branch Preview URL |
Jun 23 2026, 11:01 PM |
c4a8f04 to
8a65471
Compare
The standard varlockVitePlugin() now detects @sveltejs/adapter-cloudflare (configured in svelte.config.js or inline in vite.config) and injects the Cloudflare Workers runtime env-loader automatically, so the same import works across every deploy target. The Cloudflare-specific loader stays in @varlock/cloudflare-integration (an optional peer dep) and is pulled in lazily. - deprecate varlockSvelteKitCloudflarePlugin to a thin alias - single setup path in the SvelteKit/Cloudflare docs - add SvelteKit framework tests (build, dev, cloudflare auto-detection)
8a65471 to
f9dcd3f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.


What
SvelteKit on Cloudflare previously required a different import (
varlockSvelteKitCloudflarePluginfrom@varlock/cloudflare-integration/sveltekit) than the Node/other-adapter path (varlockVitePlugin). This makes the samevarlockVitePlugin()work for every deploy target.varlockVitePlugin()now detects@sveltejs/adapter-cloudflareand automatically injects the Cloudflare Workers runtime env-loader into the SSR entry. Detection reads the SvelteKit setup plugin's resolvedapi.options.kit.adapterinconfigResolved, so it works whether the adapter is configured insvelte.config.jsor inline invite.config(SvelteKit ≥ 2.62).adapter-autois also handled via aCF_PAGES/WORKERS_CIfallback.The Cloudflare-specific injected code stays in
@varlock/cloudflare-integrationand is pulled in lazily via a runtime dynamic import. CF deployers already have that package (it shipsvarlock-wrangler). It is intentionally not declared as a peer dependency of@varlock/vite-integration— cloudflare-integration depends on vite-integration, so the back-edge would create a Turbo build/typecheck cycle; the variable-specifier dynamic import means typecheck never needs it resolvable.Changes
@varlock/vite-integration: adapter detection + lazy loader injection (ssrEdgeRuntime+ssrEntryCode), and externalizecloudflare:workerswhen the CF Vite plugin isn't present. Logs a one-time notice when the Cloudflare adapter is detected so the auto-injection isn't silent.varlockSvelteKitCloudflarePlugin→ deprecated thin alias for back-compat.frameworks/sveltekit/fixture covering build (adapter-node), dev, Cloudflare auto-detection (incl. asserting the detection notice), and a regression guard that a fully-prerendered ("totally static") Cloudflare build still works (the injected loader stays inert in Node). All passing locally (bun run test:sveltekit).Notes for reviewers
varlockCloudflareVitePlugin, which is coupled to the ESM-only@cloudflare/vite-plugin). Detection lives in the vite plugin and only imports the dependency-free./ssr-entry-code.adapter-staticnever triggers detection (different adapter name);adapter-cloudflare+ full prerender injects the loader but it's inert at build/prerender time (guarded bynavigator.userAgent === 'Cloudflare-Workers', andcloudflare:workersis externalized + dynamically imported).codex/static-dynamic-integrationalso introduces aframework-tests/frameworks/sveltekit/fixture (adapter-static, static/dynamic feature). When both land, the two fixtures should be reconciled into one with all scenarios.varlock-examplesSvelteKit example'svite.config.tshas a matching simplification queued separately (different repo).