For v2, the recommended workflow is the @better-svelte-email/cli command-line tool. It starts a dedicated email preview server in any project folder: file watching, live reload, HTML/source views, and rendering through @better-svelte-email/server. You do not need a SvelteKit preview route.
Right now, dev is the only command the CLI provides; other subcommands may be added later.
@better-svelte-email/preview (deprecated)The @better-svelte-email/preview package (EmailPreview, createEmail, sendEmail, SvelteKit +page.server.ts wiring) is deprecated. It remains published for backward compatibility with apps that already embed the inline preview. New projects should use @better-svelte-email/cli instead.
For the classic SvelteKit-integrated flow (v1-style, legacy package), see Email Preview.
Pick one (or combine dev dependency + npx for CI).
npm install -D @better-svelte-email/cli The package exposes the bse binary in node_modules/.bin. Use npm scripts (see Run the dev server) or:
npx @better-svelte-email/cli dev npx @better-svelte-email/cli dev This downloads and runs the CLI without adding it to package.json.
npm install -g @better-svelte-email/cli
bse dev Your email templates should import primitives from @better-svelte-email/components. The CLI uses @better-svelte-email/server internally to render those components.
From the project root (where package.json lives).
Without installing the package (uses npx):
npx @better-svelte-email/cli dev After npm install -D @better-svelte-email/cli:
bse dev After a global install:
bse dev This watches src/lib/emails by default and serves the preview UI on port 3000, with JSON APIs under /api/* on the same origin. The CLI installs its internal @better-svelte-email/preview-server runtime automatically.
package.json script// package.json — "scripts"
{
"scripts": {
"email:dev": "npx @better-svelte-email/cli dev"
}
} Equivalent if the CLI is installed locally (resolves node_modules/.bin/bse):
{
"scripts": {
"email:dev": "bse dev"
}
} Then:
npm run email:dev Use Send Email in the preview toolbar (next to Copy HTML) to send a test email using your Resend API key and sender address (defaults to onboarding@resend.dev). You can optionally save credentials to .bse/resend.json in the project; otherwise they last until you stop the dev server.
See cli flags to provide credentials from the command line.
| Option | Description |
|---|---|
-p, --port <port> | Port for the preview server (default 3000) |
-d, --dir <directory> | Folder of .svelte email templates to watch (default src/lib/emails) |
-c, --custom-css-path <path> | File whose contents are passed as customCSS to the renderer (Tailwind v4 / theme parity). If omitted, the CLI tries src/app.css or src/routes/layout.css when present. |
--no-hmr | Disable live reload when templates or watched CSS change. |
--resend-api-key <key> | Resend API key for test sends from the preview UI |
--resend-from <address> | Sender for test emails (default onboarding@resend.dev) |
--resend-persist | When used with --resend-api-key, save credentials to .bse/resend.json in the project |
npx @better-svelte-email/cli dev -d src/emails npx @better-svelte-email/cli dev -c src/app.css Use Send Email in the preview toolbar (next to Copy HTML). On first use, enter your Resend API key and sender address (defaults to onboarding@resend.dev). You can optionally save credentials to .bse/resend.json in the project; otherwise they last until you stop the dev server.
From the CLI you can also pass:
bse dev --resend-api-key re_xxx --resend-from onboarding@resend.dev --resend-persist --resend-persist writes .bse/resend.json when used with --resend-api-key.
.svelte files exist under the directory passed to -d (default src/lib/emails).npx @better-svelte-email/cli dev, or bse dev if the CLI is installed globally).Pass -c to the same CSS entry you use for Tailwind v4 / variables in the app, or ensure src/app.css / src/routes/layout.css exists so the CLI can pick it up automatically.
npx @better-svelte-email/cli dev -p 3005 With --preview-dev, also set --preview-port to a free port different from -p.
If you must keep @better-svelte-email/preview in a SvelteKit app, the API surface is described in the v1 Email Preview doc (createEmail, sendEmail, emailList, etc.). Prefer migrating to npx @better-svelte-email/cli dev (or a local/global bse) when you can.