├── README.md ├── svelte5_typescript.txt ├── svelte5_snippets.txt ├── svelte_4-5_migration_guide.txt ├── svelte5_events.txt ├── svelte5_runes.txt └── svelte5_full_context.txt /README.md: -------------------------------------------------------------------------------- 1 | ## Svelte 5 for LLMs 2 | 3 | Getting LLMs to write Svelte 5 is hard and it will stay that way until more Svelte 5 code hits model training data. Until then, we’re stuck with partial understanding and workarounds. 4 | 5 | Dumping full documentation doesn’t help. It’s too big, too noisy, and wastes tokens. Most models already understand Svelte 3/4 and since Svelte 5 doesn't change everything, only the new pieces need to be shown. 6 | 7 | The official [`llms-small.txt`](https://svelte.dev/llms-small.txt) is over 130k tokens. That’s way beyond what models can reason over. Smaller contexts (think 8k–12k tokens) work best. 8 | 9 | This repo is a minimal, example-based reference focused on what changed in Svelte 5. It's written to be copy-pasted into prompts. No extra explanation, just clean annotated code. 10 | 11 | ### What's in here 12 | 13 | Each file is standalone and scoped: 14 | 15 | - [svelte5_runes.txt](./svelte5_runes.txt) — `$state`, `$effect`, `$derived`, `$bindable`, `$props`, `$host`, `$inspect` 16 | - [svelte5_events.txt](./svelte5_events.txt) — event handling, callback props, modifiers, bubbling 17 | - [svelte5_snippets.txt](./svelte5_snippets.txt) — Svelte 5 snippets (`{#snippet}`, `{@render}`), slot replacement 18 | - [svelte5_typescript.txt](./svelte5_typescript.txt) — typing props, components, DOM attributes 19 | - [svelte_4-5_migration_guide.txt](./svelte_4-5_migration_guide.txt) — what changed from Svelte 4 to 5 20 | - **[svelte5_full_context.txt](./svelte5_full_context.txt) — everything above in one file (12k tokens, works decently with most SOTA models)** 21 | -------------------------------------------------------------------------------- /svelte5_typescript.txt: -------------------------------------------------------------------------------- 1 | # Svelte 5 + TypeScript 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | --- 10 | 11 | 12 | 19 | 20 | 21 | 22 | --- 23 | 24 | ### Notes: 25 | - Adding `lang="ts"` enables TypeScript. 26 | - Type annotations (`string`) help with static checking. 27 | - No runtime overhead since TypeScript removes type annotations at compile time. 28 | 29 | --- 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | --- 38 | 39 | 40 | 47 | 48 |

Hello, {name}!

49 | 50 | --- 51 | 52 | 53 | 56 | 57 | 58 | 59 | --- 60 | 61 | ### Notes: 62 | - `Props` interface ensures `name` is always a string. 63 | - `$props()` extracts the component’s props with proper typing. 64 | 65 | --- 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | --- 74 | 75 | 76 | 84 | 85 | {#each items as item} 86 | 87 | {/each} 88 | 89 | --- 90 | 91 | 92 | 101 | 102 | 103 | 104 | --- 105 | 106 | ### Notes: 107 | - `generics="Item"` allows the component to accept any item type. 108 | - Ensures `items` and `select` function operate on the same type. 109 | 110 | --- 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | --- 119 | 120 | 121 | 128 | 129 | 130 | 131 | --- 132 | 133 | ### Notes: 134 | - `$state(0)` initializes a reactive variable with a type. 135 | - Without an initial value, TypeScript infers `number | undefined`. 136 | 137 | --- 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | --- 146 | 147 | 148 | 153 | 154 | 155 | 156 | --- 157 | 158 | 159 | 162 | 163 | 164 | 165 | --- 166 | 167 | ### Notes: 168 | - `HTMLButtonAttributes` ensures `Button.svelte` supports all standard button attributes. 169 | - `...rest` spreads remaining props onto the `