I'm trying to create a new app using SvelteKit & Cloudflare Pages and I'm struggling with running the application locally in a proper manner. Currently, in order to get the app running locally I run 2 scripts in 2 different terminals:
vite build --watch
- this creates the
cloudflare
directories in the.svelte-kit
directory vite dev
doesn't seem to create thecloudflare
directories so I've usedvite build
- this creates the
wrangler pages dev .svelte-kit/cloudflare --live-reload
- this starts the app
The above approach works, namely, it starts the app as expected. The problem is that any changes I'm making to the code are visible in the browser tab after 3-4 seconds which from a DX point of view is far from enjoying. Ideally, when running locally, any code changes should be visible in the browser tab in 1-sec-ish.
This is the first time I'm tinkering with SvelteKit & Cloudflare Pages so I'm sure I'm missing something. Therefore, the question is: how should one run a SvelteKit & Cloudflare Pages app locally "the right way"? "The right way" means that I can see the effect of my code changes in 1-sec-ish and I can run the app locally using something like wrangler
or miniflare
in order for the local environment to resemble as much as possible the production one.
P.s.: I've checked docs like https://developers.cloudflare.com/pages/framework-guides/deploy-a-svelte-site/ and https://www.npmjs.com/package/@sveltejs/adapter-cloudflare readme.md
but they focus mainly on how to run the app in production
P.p.s: I believe the 2 scripts can be merged into a single one using something like concurrently but at the moment my focus is on having quick feedback when it comes to code changes
P.p.p.s.: bundling and tinkering with the javascript modules themselves is not one of my strong points yet so if you have any helpful articles, they're more than welcome
vite dev
command doesn't do any bundling, butvite build
bundles all the code with Rollup, which makes it comparably slow. I sympathize with your wish to make the local environment resemble the production one, but if I understand the Cloudflare pages adapter correctly it "just" compiles the SvelteKit server endpoints into a single_worker.js
file in production, so if runningvite dev
locally differs from the production environment in functionality it will be a bug in the framework. – Judejudea