Skip to content

Commit

Permalink
Update Svelte integration v6 docs (#10002)
Browse files Browse the repository at this point in the history
Co-authored-by: Sarah Rainsberger <[email protected]>
Co-authored-by: casungo <[email protected]>
  • Loading branch information
3 people authored Nov 15, 2024
1 parent e9934f8 commit eb0795f
Showing 1 changed file with 8 additions and 24 deletions.
32 changes: 8 additions & 24 deletions src/content/docs/en/guides/integrations-guide/svelte.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ i18nReady: true
import PackageManagerTabs from '~/components/tabs/PackageManagerTabs.astro';
import Since from '~/components/Since.astro';

This **[Astro integration][astro-integration]** enables server-side rendering and client-side hydration for your [Svelte](https://svelte.dev/) components. It supports Svelte 3, 4, and 5 (experimental).
This **[Astro integration][astro-integration]** enables server-side rendering and client-side hydration for your [Svelte](https://svelte.dev/) 5 components. For Svelte 3 and 4 support, install `@astrojs/svelte@5` instead.

## Installation

Expand Down Expand Up @@ -103,44 +103,28 @@ To use your first Svelte component in Astro, head to our [UI framework documenta

This integration is powered by `@sveltejs/vite-plugin-svelte`. To customize the Svelte compiler, options can be provided to the integration. See the [`@sveltejs/vite-plugin-svelte` docs](https://github.com/sveltejs/vite-plugin-svelte/blob/HEAD/docs/config.md) for more details.

### Default options
You can set options either by passing them to the `svelte` integration in `astro.config.mjs` or in `svelte.config.js`. The options in `astro.config.mjs` will take precedence over the options in `svelte.config.js` if both are present:

This integration passes the following default options to the Svelte compiler:

```js
const defaultOptions = {
emitCss: true,
compilerOptions: { dev: isDev, hydratable: true },
preprocess: vitePreprocess(),
};
```

These `emitCss`, `compilerOptions.dev`, and `compilerOptions.hydratable` values are required to build properly for Astro and cannot be overridden.

Providing your own `preprocess` options **will** override the [`vitePreprocess()`](https://github.com/sveltejs/vite-plugin-svelte/blob/HEAD/docs/preprocess.md) default. Make sure to enable the preprocessor flags needed for your project.

You can set options either by passing them to the `svelte` integration in `astro.config.mjs` or in `svelte.config.js`. Either of these would override the default `preprocess` setting:

```js title="astro.config.mjs" "preprocess: []"
```js title="astro.config.mjs" "extensions: ['.svelte']"
import { defineConfig } from 'astro/config';
import svelte from '@astrojs/svelte';

export default defineConfig({
integrations: [svelte({ preprocess: [] })],
integrations: [svelte({ extensions: ['.svelte'] })],
});
```

```js title="svelte.config.js"
export default {
preprocess: [],
extensions: ['.svelte'],
};
```

## Intellisense for TypeScript
## Preprocessors

<Since v="2.0.0" pkg="@astrojs/svelte" />

If you're using a preprocessor like TypeScript or SCSS in your Svelte files, you can create a `svelte.config.js` file so that the Svelte IDE extension can correctly parse the Svelte files.
If you're using SCSS or Stylus in your Svelte files, you can create a `svelte.config.js` file so that they are preprocessed by Svelte, and the Svelte IDE extension can correctly parse the Svelte files.

```js title="svelte.config.js"
import { vitePreprocess } from '@astrojs/svelte';
Expand All @@ -150,7 +134,7 @@ export default {
};
```

This config file will be automatically added for you when you run `astro add svelte`.
This config file will be automatically added for you when you run `astro add svelte`. See the [`@sveltejs/vite-plugin-svelte` docs](https://github.com/sveltejs/vite-plugin-svelte/blob/HEAD/docs/preprocess.md) for more details about `vitePreprocess`.

[astro-integration]: /en/guides/integrations-guide/

Expand Down

0 comments on commit eb0795f

Please sign in to comment.