Sveltekit
Skill VRIL-LABS/skill-jam/skills/ai-ml/skills-main-2/skills-main/sveltekit
Welcome to the skill-jam βοΈπ
npx -y skills add VRIL-LABS/skill-jam --skill sveltekitAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
2 things to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Expert guidance for SvelteKit development with TypeScript, Tailwind CSS, SSR/SSG, and performance optimization best practices
SKILL.md
6.3 KB, ~1.6k tokens by cl100k_base, as published. Nobody here has run it
SvelteKit Development
You are an expert in SvelteKit, TypeScript, Tailwind CSS, and modern web application development.
Key Principles
- Write concise, technical SvelteKit code with accurate TypeScript examples
- Use functional and declarative programming patterns; avoid classes
- Prefer iteration and modularization over code duplication
- Use descriptive variable names with auxiliary verbs (isLoading, hasError)
- Structure files: component logic, markup, styles, helpers, types
Project Structure
src/
βββ lib/
β βββ components/ # Reusable Svelte components
β βββ server/ # Server-only utilities
β βββ stores/ # Svelte stores
β βββ utils/ # Shared utilities
βββ routes/
β βββ +layout.svelte # Root layout
β βββ +page.svelte # Home page
β βββ api/ # API routes
βββ app.html # HTML template
βββ app.css # Global styles
Component Development
Script Setup with TypeScript
<script lang="ts">
import { onMount } from 'svelte';
import type { PageData } from './$types';
export let data: PageData;
let count = 0;
$: doubled = count * 2;
function increment() {
count += 1;
}
</script>
Props and Events
<script lang="ts">
import { createEventDispatcher } from 'svelte';
export let title: string;
export let disabled = false;
const dispatch = createEventDispatcher<{
submit: { value: string };
}>();
function handleSubmit() {
dispatch('submit', { value: title });
}
</script>
Routing
File-Based Routes
routes/
βββ +page.svelte # /
βββ about/+page.svelte # /about
βββ blog/
β βββ +page.svelte # /blog
β βββ [slug]/
β βββ +page.svelte # /blog/:slug
Dynamic Routes
<!-- routes/blog/[slug]/+page.svelte -->
<script lang="ts">
import type { PageData } from './$types';
export let data: PageData;
</script>
<h1>{data.post.title}</h1>
Load Functions
// +page.server.ts
import type { PageServerLoad } from './$types';
export const load: PageServerLoad = async ({ params, fetch }) => {
const response = await fetch(`/api/posts/${params.slug}`);
const post = await response.json();
return { post };
};
SSR and SSG
Server-Side Rendering
// +page.server.ts
export const ssr = true;
export const csr = true;
export const load: PageServerLoad = async ({ locals }) => {
return {
user: locals.user
};
};
Static Generation
// +page.ts
export const prerender = true;
export async function load() {
return {
// Static data
};
}
Prerendering Dynamic Routes
// +page.server.ts
export const prerender = true;
export async function entries() {
const posts = await getPosts();
return posts.map((post) => ({ slug: post.slug }));
}
Form Actions
// +page.server.ts
import type { Actions } from './$types';
export const actions: Actions = {
default: async ({ request, cookies }) => {
const data = await request.formData();
const email = data.get('email');
// Validate and process
if (!email) {
return { success: false, error: 'Email required' };
}
return { success: true };
}
};
<!-- +page.svelte -->
<script lang="ts">
import { enhance } from '$app/forms';
import type { ActionData } from './$types';
export let form: ActionData;
</script>
<form method="POST" use:enhance>
<input name="email" type="email" />
<button type="submit">Subscribe</button>
{#if form?.error}
<p class="error">{form.error}</p>
{/if}
</form>
State Management
Svelte Stores
// lib/stores/counter.ts
import { writable, derived } from 'svelte/store';
export const count = writable(0);
export const doubled = derived(count, ($count) => $count * 2);
export function increment() {
count.update((n) => n + 1);
}
Page Store
<script lang="ts">
import { page } from '$app/stores';
$: currentPath = $page.url.pathname;
$: params = $page.params;
</script>
API Routes
// routes/api/posts/+server.ts
import { json } from '@sveltejs/kit';
import type { RequestHandler } from './$types';
export const GET: RequestHandler = async ({ url }) => {
const limit = url.searchParams.get('limit') ?? '10';
const posts = await getPosts(Number(limit));
return json(posts);
};
export const POST: RequestHandler = async ({ request }) => {
const body = await request.json();
const post = await createPost(body);
return json(post, { status: 201 });
};
Styling with Tailwind
<div class="flex flex-col gap-4 p-6">
<h1 class="text-2xl font-bold text-gray-900 dark:text-white">
{title}
</h1>
<p class="text-gray-600 dark:text-gray-300">
{description}
</p>
</div>
<style>
/* Scoped styles when needed */
:global(.prose) {
@apply max-w-none;
}
</style>
Error Handling
<!-- +error.svelte -->
<script lang="ts">
import { page } from '$app/stores';
</script>
<h1>{$page.status}</h1>
<p>{$page.error?.message}</p>
// +page.server.ts
import { error } from '@sveltejs/kit';
export const load: PageServerLoad = async ({ params }) => {
const post = await getPost(params.slug);
if (!post) {
throw error(404, 'Post not found');
}
return { post };
};
Performance Optimization
- Use
{#key}blocks for component recreation - Implement lazy loading with dynamic imports
- Use
$effect.prefor DOM measurements - Optimize images with
@sveltejs/enhanced-img - Prefetch links with
data-sveltekit-preload-data
Testing
// Component testing with Vitest
import { render, screen } from '@testing-library/svelte';
import { expect, test } from 'vitest';
import Button from './Button.svelte';
test('renders button with text', () => {
render(Button, { props: { label: 'Click me' } });
expect(screen.getByRole('button')).toHaveTextContent('Click me');
});
Accessibility
- Use semantic HTML elements
- Add ARIA labels where needed
- Ensure keyboard navigation
- Test with screen readers
- Maintain focus management