Cookbook

This cookbook serves shows users how best-in-practice code is written in Svelte. You’ll learn how to import third-party libraries, external scripts as well as how to handle common problems that you will have to solve often.

What can I expect from these recipes?

The Svelte compiler expects all components it receives to be valid Svelte syntax. To use compile-to-js or compile-to-css languages, you need to make sure that any non-standard syntax is transformed before Svelte tries to parse it. To enable this Svelte provides a preprocess method allowing you to transform different parts of the component before it reaches the compiler. With svelte.preprocess you have a great deal of flexibility in how you write your components while ensuring that the Svelte compiler receives a plain component.

Where to get started

If you want the quickest way to get started, clone the Official Svelte App template. If you want a custom setup, head to the Build Setup recipes.

If you are writing a Svelte component library, check the the Official Svelte Component template.