feat(cloudflare): add SvelteKit + Cloudflare Vite plugin#622
Open
theoephraim wants to merge 3 commits intomainfrom
Open
feat(cloudflare): add SvelteKit + Cloudflare Vite plugin#622theoephraim wants to merge 3 commits intomainfrom
theoephraim wants to merge 3 commits intomainfrom
Conversation
Adds `varlockSvelteKitCloudflarePlugin` exported at `@varlock/cloudflare-integration/sveltekit` for SvelteKit projects deploying to Cloudflare Workers via `@sveltejs/adapter-cloudflare`. The existing `varlockCloudflareVitePlugin` wraps `@cloudflare/vite-plugin`, which doesn't currently support SvelteKit. The new plugin skips that wrapper while still injecting a `cloudflare:workers` env loader into the SvelteKit SSR entry — guarded by a `navigator.userAgent` check and a dynamic import so SvelteKit's Node-side postbuild steps don't fail resolving `cloudflare:workers`. The shared env-loader body (reading `__VARLOCK_ENV` / chunked bindings from `cloudflare:workers` env and stashing it on `globalThis.__varlockLoadedEnv`) is extracted to `shared-ssr-entry-code.ts` and reused by both variants. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: ca9209f The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
varlock-website | be4cdcf | Commit Preview URL Branch Preview URL |
Apr 16 2026, 06:54 AM |
- Add a new SvelteKit integration page. For most adapters it routes users to the Vite integration; for Cloudflare Workers it documents `varlockSvelteKitCloudflarePlugin` setup and the Workers Builds dashboard configuration (overriding the Deploy command, setting secret-zero vars in Build variables). - Register the new page in the sidebar and the integrations overview. - Add a small callout on the Cloudflare integration page pointing SvelteKit users to the SvelteKit guide instead of the two existing approaches. - Add a Cloudflare Workers Builds (CI/CD) section to the Cloudflare integration page with the same dashboard-configuration guidance. - Clarify on the Vite integration page that projects with SSR/server code on Cloudflare Workers should use the Cloudflare integration (not the plain Vite plugin) so secrets aren't bundled into the worker. - Update the package README to list the SvelteKit variant. - Drop the "new" badge on the Bun entry; add one on SvelteKit. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
9d11aa2 to
be4cdcf
Compare
Two Vitest worker processes (e.g. cloudflare-vite + wrangler tests) could race on the same `.packed/<pkg>.tgz` output path, producing a corrupted tarball and failing `bun install` with ZlibError. Add a per-package file-based mutex (atomic mkdir) around the pack step so the second worker reuses the first worker's tarball. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
| // Pack the package | ||
| const fullPackageDir = join(REPO_ROOT, packageDir); | ||
| console.log(`[pack] Packing ${name}...`); | ||
| execSync(`bun pm pack --destination ${PACKED_DIR}`, { |
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.
Summary
varlockSvelteKitCloudflarePluginexported from@varlock/cloudflare-integration/sveltekitfor SvelteKit projects deployed to Cloudflare Workers via@sveltejs/adapter-cloudflare.varlockCloudflareVitePluginwraps@cloudflare/vite-plugin, which doesn't currently play nicely with SvelteKit (cloudflare/workers-sdk#8922). The new variant skips that wrapper while still injecting acloudflare:workersenv loader into the SvelteKit SSR entry (@sveltejs/kit/.../runtime/server/index.js, which adapter-cloudflare's generated_worker.jsimports).navigator.userAgent === 'Cloudflare-Workers'and uses a dynamic import so SvelteKit's Node-side postbuild steps (prerender, fallback) don't fail resolvingcloudflare:workers.__VARLOCK_ENV/ chunked bindings →globalThis.__varlockLoadedEnv) intoshared-ssr-entry-code.tsand reuses it from both plugin variants. The existing Workers-only plugin keeps its synchronous static import — no runtime behavior change there.Why two variants instead of a flag
The two paths have effectively no overlap at runtime (different entry module, different dev story, different Vite plugin composition). A separate subpath export keeps the docs, errors, and types clean.
Test plan
bun run buildinpackages/integrations/cloudflarenpm run buildon thesveltekit-on-cloudflareexample — SSR entry contains the guarded loader, staticimport 'cloudflare:workers'is preserved as externalbun run lint:fixcleanvarlock-wrangler deployand verify env resolves at runtime in a real Worker🤖 Generated with Claude Code