Demo 👉 blogmdsvex.vercel.app
Repo 👉 GitHub
This project demonstrates how to build a fully prerendered blog using:
- SvelteKit 2
- Svelte 5
- MDsveX 0.12.3
- Tailwind CSS 4
Most existing MDsveX tutorials and examples are still based on Svelte 4, so this repo aims to provide an up-to-date example for Svelte 5.
To build a prerendered blog with Svelte we can use MDsveX.
npx sv createFor more context for the next steps, refer to this commit.
Create a /content folder at the root of your project and place your markdown blog posts inside. Each file should be named in kebab-case format like:
content/
├─ hello-world-intro.md
├─ my-second-post.md
Create a /src/routes/+layout.server.ts file with the following:
export const prerender = true;Update your svelte.config.js with the proper MDsveX setup and supported extensions:
import { mdsvex } from "mdsvex";
// ...
const config = {
preprocess: [vitePreprocess(), mdsvex({ extensions: [".md"] })],
extensions: [".svelte", ".md"],
// ...
};
export default config;Create these two routes:
Home page (list of posts):
Post detail page (by slug):
npm run build
npm run previewIf you get errors accessing local markdown files in dev mode, update vite.config.ts:
export default defineConfig(({ mode }) => ({
plugins: [tailwindcss(), sveltekit()],
server: {
fs: {
allow: mode === "development" ? ["."] : [],
},
},
}));This template shows how to:
Load markdown content at build time
Use MDsveX to write posts in .md
Generate static pages with prerender = true
Inspired by https://github.com/wiscaksono/wiscaksono-site (wiscaksono)
Feel free to fork and adapt this project. PRs are welcome. Licensed under MIT.