Skip to content

A basic starter project for working locally in sveltekit on Cloudflare

License

Notifications You must be signed in to change notification settings

sdarnell/cf-svelte

Folders and files

NameName
Last commit message
Last commit date

Latest commit

3883b8d · Oct 15, 2024

History

19 Commits
Feb 20, 2024
Sep 26, 2023
Oct 15, 2024
Sep 25, 2023
Sep 25, 2023
Sep 25, 2023
Oct 15, 2024
Sep 25, 2023
Sep 25, 2023
Feb 20, 2024
Oct 15, 2024
Oct 15, 2024
Oct 15, 2024
Sep 25, 2023
Dec 15, 2023
Sep 25, 2023
Oct 15, 2024
Sep 29, 2023

Repository files navigation

Sveltekit starter for Cloudflare that allows easier local development

This starter was initially created with C3 (Create Cloudflare CLI), and then enhanced with a few things:

  • Allow npm start to start a local dev environment (same as npm run dev)
  • Support for a trusted SSL cert using mkcert
  • Add the Svelte Inspector
  • Add an example migration for the database

create-svelte

The initial project was created with:

npm create cloudflare@latest cf-svelte -- --framework=svelte

mkcert

To get a trusted SSL certificate when testing locally, we use the mkcert package, see https://github.com/FiloSottile/mkcert

If you haven't used it before, you will need install it the first time.

$ mkcert -install
Created a new local CA
The local CA is now installed in the system trust store!
The local CA is now installed in the Firefox trust store (requires browser restart)!

Then your app can use a local cert with a shorter lifespan. These are stored in the .cert directory, and can be setup or refreshed with:

npm run cert

Svelte inspector

When running locally you can enable the inspector by pressing Cmd ⌘ + Shift ⇧ on Mac, otherwise Ctrl ⌃ + Shift ⇧. Then highlight and click on components.

See https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/inspector.md

D1 Migration

To apply the recorded migrations, use:

$ npm run migration:add
or
$ npx wrangler d1 migrations apply DB --local
Migrations to be applied:
┌──────────────────┐
│ name             │
├──────────────────┤
│ 0000_initial.sql │
└──────────────────┘
? About to apply 1 migration(s)
Your database may not be available to serve requests during the migration, continue? › (Y/n)
o Mapping SQL input into an array of statements
o Loading f6c5717c-3866-45d3-b4e7-20b332e359e0 from .wrangler/state/v3/d1
┌──────────────────┬────────┐
│ name             │ status │
├──────────────────┼────────┤
│ 0000_initial.sql │ (tick) │
└──────────────────┴────────┘

About

A basic starter project for working locally in sveltekit on Cloudflare

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published