--- title: 'svelte/compiler' --- Typically, you won't interact with the Svelte compiler directly, but will instead integrate it into your build system using a bundler plugin. The bundler plugin that the Svelte team most recommends and invests in is [vite-plugin-svelte](https://github.com/sveltejs/vite-plugin-svelte). The [SvelteKit](https://kit.svelte.dev/) framework provides a setup leveraging `vite-plugin-svelte` to build applications as well as a [tool for packaging Svelte component libraries](https://kit.svelte.dev/docs/packaging). Svelte Society maintains a list of [other bundler plugins](https://sveltesociety.dev/tools/#bundling) for additional tools like Rollup and Webpack. Nonetheless, it's useful to understand how to use the compiler, since bundler plugins generally expose compiler options to you. ## compile > EXPORT_SNIPPET: svelte/compiler#compile This is where the magic happens. `svelte.compile` takes your component source code, and turns it into a JavaScript module that exports a class. ```js // @filename: ambient.d.ts declare global { var source: string } export {} // @filename: index.ts // ---cut--- import { compile } from 'svelte/compiler'; const result = compile(source, { // options }); ``` Refer to [CompileOptions](#types-compileoptions) for all the available options. The returned `result` object contains the code for your component, along with useful bits of metadata. ```ts // @filename: ambient.d.ts declare global { const source: string; } export {}; // @filename: main.ts import { compile } from 'svelte/compiler'; // ---cut--- const { js, css, ast, warnings, vars, stats } = compile(source); ``` Refer to [CompileResult](#types-compileresult) for a full description of the compile result. ## parse > EXPORT_SNIPPET: svelte/compiler#parse The `parse` function parses a component, returning only its abstract syntax tree. Unlike compiling with the `generate: false` option, this will not perform any validation or other analysis of the component beyond parsing it. Note that the returned AST is not considered public API, so breaking changes could occur at any point in time. ```js // @filename: ambient.d.ts declare global { var source: string; } export {}; // @filename: main.ts // ---cut--- import { parse } from 'svelte/compiler'; const ast = parse(source, { filename: 'App.svelte' }); ``` ## preprocess > EXPORT_SNIPPET: svelte/compiler#preprocess A number of [official and community-maintained preprocessing plugins](https://sveltesociety.dev/tools#preprocessors) are available to allow you to use Svelte with tools like TypeScript, PostCSS, SCSS, and Less. You can write your own preprocessor using the `svelte.preprocess` API. The `preprocess` function provides convenient hooks for arbitrarily transforming component source code. For example, it can be used to convert a `