-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update Svelte integration v6 docs #10002
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note there are now no default options set by Astro. It falls back to the behaviour in Which means the notes about |
||
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. | ||
Comment on lines
-143
to
+127
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed references to TypeScript here as Svelte 5 now handles TypeScript by default even without |
||
|
||
```js title="svelte.config.js" | ||
import { vitePreprocess } from '@astrojs/svelte'; | ||
|
@@ -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/ | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just calling attention to it because it looks weird. Svelte 5 is the default. If you want 3 and install
svelte@**5**
-- just checking this isn't a typo or something!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's referring to install
@astrojs/svelte
, which is an integration. And@astrojs/svelte
v5 supports Svelte 3 and 4 only.Svelte 5 support is added on
@astrojs/svelte
v6, which I didn't mention v6 here since it will be the latest.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, figured this out in the other PR. What a pain, but understood!
Would be much nicer if our numbers aligned with theirs!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Easy, just don't ship @astrojs/svelte v6 and update v5 until Svelte v6 drops.