tezvyn:

SvelteKit Server-Only Modules: Keep Your Secrets Secret

Source: svelte.devadvanced

SvelteKit's server-only modules are a firewall for your code, preventing sensitive data like API keys from ever being bundled for the browser. Use them for database clients or secret logic.

SvelteKit's server-only modules are a compile-time firewall, preventing sensitive backend code from accidentally leaking into your client-side bundle. Mark modules as server-only by placing them in `$lib/server/` or naming them with `.server.js`. This is essential for protecting database clients, private API keys, or filesystem access. The check is strict: if a client component imports a utility file that *also* imports from a server-only module, the build will fail, even if the sensitive part isn't directly used.

Read the original → svelte.dev

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

SvelteKit Server-Only Modules: Keep Your Secrets Secret · Tezvyn