Mikkel Svartveit
CDCloudflare Developers
•Created by Mikkel Svartveit on 4/9/2025 in #workers-help
Separate build-time variables per environment
Hi! I'm trying to migrate my SvelteKit app from Cloudflare Pages to Cloudflare Workers and Workers Builds. However, I'm having some issues with build-time environment variables.
SvelteKit supports client-side environment variables by importing from
$env/static/public
. However, these need to be available at build time because they are injected into the static Vite bundle.
With Cloudflare Pages, this was easy to handle, since the specified environment variables were available both at build-time and at run-time. However, with Workers and Workers Builds, I understand that environment variables specified in the dashboard or in the wrangler.jsonc file are only available at run-time, not at build-time.
I see there is an option in the dashboard for specifying build-time variables. However, I need to have separate variables for my different environments (staging, production, etc.). I can't find a way to do this with Workers Builds, and it's currently blocking me from migrating from Cloudflare Pages. Is there any way to achieve this?2 replies