Skip to content

Commit fd78385

Browse files
authored
chore: restructure docs for new site (#13699)
1 parent ad578a5 commit fd78385

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+2125
-799
lines changed

.prettierignore

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# Temporarily ignore this file to avoid merge conflicts.
2-
# see: https://github.com/sveltejs/svelte/pull/9609
3-
documentation/docs/05-misc/03-typescript.md
1+
documentation/docs/
42

53
packages/**/dist/*.js
64
packages/**/build/*.js

documentation/blog/2020-07-17-svelte-and-typescript.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ We think it'll give you a much nicer development experience — one that also sc
1616

1717
## Try it now
1818

19-
You can start a new Svelte TypeScript project using Svelte's official scaffolding CLI by running `npm create svelte@latest` and following the prompts. This sets up a new SvelteKit project for you.
19+
You can start a new Svelte TypeScript project using Svelte's official scaffolding CLI by running `npx sv create` and following the prompts. This sets up a new SvelteKit project for you.
2020

2121
Alternatively you can run `npm create vite@latest myapp -- --template svelte-ts` to scaffold a Vite project using Svelte and TypeScript.
2222

documentation/blog/2022-12-14-announcing-sveltekit-1.0.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ After two years in development, [SvelteKit](https://kit.svelte.dev) has finally
99

1010
We’re so excited to share this release with you. It’s the culmination of thousands of hours of work, both from the Svelte core team and the wider community, and we think it’s the most enjoyable way to build production-grade websites, whether you’re a solo developer working on a small project or part of a large team.
1111

12-
To get started, run `npm create svelte@latest`, and visit the [docs](https://kit.svelte.dev/docs) and (experimental!) [interactive tutorial](https://learn.svelte.dev).
12+
To get started, run `npm sv create`, and visit the [docs](https://kit.svelte.dev/docs) and (experimental!) [interactive tutorial](https://learn.svelte.dev).
1313

1414
<div class="max">
1515
<figure style="max-width: 960px; margin: 0 auto">

documentation/blog/2023-06-22-svelte-4.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ After months in the making, we're excited to announce the stable release of Svel
99

1010
Time flies - Svelte 3 was released more than four years ago! In JavaScript-framework-time, that's eons. Svelte’s freshness has persisted throughout, but Node.js and browser APIs have evolved during that time and today we’re updating Svelte to take advantage of some of these improvements. Svelte 4 is mainly a maintenance release, bumping minimum version requirements and tightening up the design in specific areas. It sets the stage for the next generation of Svelte to be released as Svelte 5 - we think you’ll love it.
1111

12-
If you haven't tried Svelte yet, take it for a spin in our [interactive tutorial](https://learn.svelte.dev/), on [StackBlitz](https://sveltekit.new/), or locally with `npm create svelte@latest`. Svelte lets you easily put together web UIs leveraging the power of HTML, CSS, JS, and the Svelte compiler. Watch [Svelte Radio Live](https://www.youtube.com/watch?v=72TIVhRtyWE) to learn more about this release.
12+
If you haven't tried Svelte yet, take it for a spin in our [interactive tutorial](https://learn.svelte.dev/), on [StackBlitz](https://sveltekit.new/), or locally with `npx sv create`. Svelte lets you easily put together web UIs leveraging the power of HTML, CSS, JS, and the Svelte compiler. Watch [Svelte Radio Live](https://www.youtube.com/watch?v=72TIVhRtyWE) to learn more about this release.
1313

1414
## What's new
1515

@@ -40,7 +40,7 @@ Stay tuned for a more in-depth blog post about all the site changes in the comin
4040

4141
## Migrating
4242

43-
Most apps and libraries that are compatible with Svelte 3 should be compatible with Svelte 4. Library authors will need to update the version range to include Svelte 4 if `svelte` is specified in the `peerDependencies`. For application authors, the most common change required will be updating tooling to meet the new minimum version requirements such as Node.js 16. Many other migration steps can be handled with `npx svelte-migrate@latest svelte-4`.
43+
Most apps and libraries that are compatible with Svelte 3 should be compatible with Svelte 4. Library authors will need to update the version range to include Svelte 4 if `svelte` is specified in the `peerDependencies`. For application authors, the most common change required will be updating tooling to meet the new minimum version requirements such as Node.js 16. Many other migration steps can be handled with `npx sv migrate svelte-4`.
4444

4545
Read the [migration guide](/docs/v4-migration-guide) for full details.
4646

documentation/blog/2023-08-31-view-transitions.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ With that out of the way, let's see how you can use view transitions in your Sve
5454

5555
## Getting started with view transitions
5656

57-
The best way to see view transitions in action is to try it yourself. You can spin up the SvelteKit demo app by running `npm create svelte@latest` in your local terminal, or in your browser on [StackBlitz](https://sveltekit.new). Make sure to use a browser that supports the view transitions API. Once you have the app running, add the following to the script block in `src/routes/+layout.svelte`.
57+
The best way to see view transitions in action is to try it yourself. You can spin up the SvelteKit demo app by running `npx sv create` in your local terminal, or in your browser on [StackBlitz](https://sveltekit.new). Make sure to use a browser that supports the view transitions API. Once you have the app running, add the following to the script block in `src/routes/+layout.svelte`.
5858

5959
```js
6060
// @errors: 2305 7006 2339 2810

documentation/docs/01-introduction/01-overview.md

+16-16
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,29 @@
22
title: Overview
33
---
44

5-
- Short intro to what Svelte is and why it's the best ever
6-
- A few code examples to have a very rough understanding of how Svelte code looks like
7-
- Jump off points to tutorial, SvelteKit etc
8-
9-
Svelte is a web UI framework that uses a compiler to turn declarative component code like this...
5+
Svelte is a framework for building user interfaces on the web. It uses a compiler to turn declarative components written in HTML, CSS and JavaScript...
106

117
```svelte
128
<!--- file: App.svelte --->
13-
<script lang="ts">
14-
let count = $state(0);
15-
16-
function increment() {
17-
count += 1;
9+
<script>
10+
function greet() {
11+
alert('Welcome to Svelte!');
1812
}
1913
</script>
2014
21-
<button onclick={increment}>
22-
clicks: {count}
23-
</button>
15+
<button onclick={greet}>click me</button>
16+
17+
<style>
18+
button {
19+
font-size: 2em;
20+
}
21+
</style>
2422
```
2523

26-
...into tightly optimized JavaScript that updates the document when state like count changes. Because the compiler can 'see' where count is referenced, the generated code is highly efficient, and because we're hijacking syntax like `$state(...)` and `=` instead of using cumbersome APIs, you can write less code.
24+
...into lean, tightly optimized JavaScript.
25+
26+
You can use it to build anything on the web, from standalone components to ambitious full stack apps (using Svelte's companion application framework, [SvelteKit](../kit)) and everything in between.
2727

28-
Besides being fun to work with, Svelte offers a lot of features built-in, such as animations and transitions. Once you've written your first components you can reach for our batteries included metaframework [SvelteKit](../kit) which provides you with an opinionated router, data loading and more.
28+
These pages serve as reference documentation. If you're new to Svelte, we recommend starting with the [interactive tutorial](/tutorial) and coming back here when you have questions.
2929

30-
If you're new to Svelte, visit the [interactive tutorial](/tutorial) before consulting this documentation. You can try Svelte online using the [REPL](/repl). Alternatively, if you'd like a more fully-featured environment, you can try Svelte on [StackBlitz](https://sveltekit.new).
30+
You can also try Svelte online in the [playground](/playground) or, if you need a more fully-featured environment, on [StackBlitz](https://sveltekit.new).

documentation/docs/01-introduction/02-getting-started.md

+5-15
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,27 @@
22
title: Getting started
33
---
44

5-
- `npm create svelte@latest`, describe that it scaffolds SvelteKit project
6-
- `npm create vite@latest`, describe that it scaffolds Svelte SPA powered by Vite
7-
- mention `svelte-add`
8-
- Jump off points to tutorial, SvelteKit etc
9-
10-
## Start a new project
11-
12-
We recommend using [SvelteKit](https://kit.svelte.dev/), the official application framework from the Svelte team:
5+
We recommend using [SvelteKit](https://kit.svelte.dev/), the official application framework from the Svelte team powered by [Vite](https://vite.dev/):
136

147
```
15-
npm create svelte@latest myapp
8+
npx sv create myapp
169
cd myapp
17-
npm install
1810
npm run dev
1911
```
2012

21-
SvelteKit will handle calling [the Svelte compiler](https://www.npmjs.com/package/svelte) to convert your `.svelte` files into `.js` files that create the DOM and `.css` files that style it. It also provides all the other pieces you need to build a web application such as a development server, routing, deployment, and SSR support. [SvelteKit](https://kit.svelte.dev/) uses [Vite](https://vitejs.dev/) to build your code.
22-
2313
Don't worry if you don't know Svelte yet! You can ignore all the nice features SvelteKit brings on top for now and dive into it later.
2414

2515
### Alternatives to SvelteKit
2616

27-
If you don't want to use SvelteKit for some reason, you can also use Svelte with Vite (but without SvelteKit) by running `npm create vite@latest` and selecting the `svelte` option. With this, `npm run build` will generate HTML, JS and CSS files inside the `dist` directory thanks using [vite-plugin-svelte](https://github.com/sveltejs/vite-plugin-svelte). In most cases, you will probably need to [choose a routing library](faq#Is-there-a-router) as well.
17+
You can also use Svelte directly with Vite by running `npm create vite@latest` and selecting the `svelte` option. With this, `npm run build` will generate HTML, JS and CSS files inside the `dist` directory using [vite-plugin-svelte](https://github.com/sveltejs/vite-plugin-svelte). In most cases, you will probably need to [choose a routing library](faq#Is-there-a-router) as well.
2818

29-
Alternatively, there are plugins for [Rollup](https://github.com/sveltejs/rollup-plugin-svelte), [Webpack](https://github.com/sveltejs/svelte-loader) [and a few others](https://sveltesociety.dev/packages?category=build-plugins) to handle Svelte compilation — which will output `.js` and `.css` that you can insert into your HTML — but setting up SSR with them requires more manual work.
19+
There are also plugins for [Rollup](https://github.com/sveltejs/rollup-plugin-svelte), [Webpack](https://github.com/sveltejs/svelte-loader) [and a few others](https://sveltesociety.dev/packages?category=build-plugins), but we recommend Vite.
3020

3121
## Editor tooling
3222

3323
The Svelte team maintains a [VS Code extension](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode) and there are integrations with various other [editors](https://sveltesociety.dev/resources#editor-support) and tools as well.
3424

35-
You can also check your code from the command line using [svelte-check](https://www.npmjs.com/package/svelte-check) (using the Svelte or Vite CLI setup will install this for you).
25+
You can also check your code from the command line using [sv check](https://github.com/sveltejs/cli).
3626

3727
## Getting help
3828

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
title: .svelte files
3+
---
4+
5+
Components are the building blocks of Svelte applications. They are written into `.svelte` files, using a superset of HTML.
6+
7+
All three sections — script, styles and markup — are optional.
8+
9+
<!-- prettier-ignore -->
10+
```svelte
11+
/// file: MyComponent.svelte
12+
<script module>
13+
// module-level logic goes here
14+
// (you will rarely use this)
15+
</script>
16+
17+
<script>
18+
// instance-level logic goes here
19+
</script>
20+
21+
<!-- markup (zero or more items) goes here -->
22+
23+
<style>
24+
/* styles go here */
25+
</style>
26+
```
27+
28+
## `<script>`
29+
30+
A `<script>` block contains JavaScript (or TypeScript, when adding the `lang="ts"` attribute) that runs when a component instance is created. Variables declared (or imported) at the top level can be referenced in the component's markup.
31+
32+
In addition to normal JavaScript, you can use _runes_ to declare [component props]($props) and add reactivity to your component. Runes are covered in the next section.
33+
34+
<!-- TODO describe behaviour of `export` -->
35+
36+
## `<script module>`
37+
38+
A `<script>` tag with a `module` attribute runs once when the module first evaluates, rather than for each component instance. Variables declared in this block can be referenced elsewhere in the component, but not vice versa.
39+
40+
```svelte
41+
<script module>
42+
let total = 0;
43+
</script>
44+
45+
<script>
46+
total += 1;
47+
console.log(`instantiated ${total} times`);
48+
</script>
49+
```
50+
51+
You can `export` bindings from this block, and they will become exports of the compiled module. You cannot `export default`, since the default export is the component itself.
52+
53+
## `<style>`
54+
55+
CSS inside a `<style>` block will be scoped to that component.
56+
57+
```svelte
58+
<style>
59+
p {
60+
/* this will only affect <p> elements in this component */
61+
color: burlywood;
62+
}
63+
</style>
64+
```
65+
66+
For more information regarding styling, read the documentation around [styles and classes](styles-and-classes).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
title: .svelte.js and .svelte.ts files
3+
---
4+
5+
Besides `.svelte` files, Svelte also operates on `.svelte.js` and `.svelte.ts` files.
6+
7+
These behave like any other `.js` or `.ts` module, except that you can use runes. This is useful for creating reusable reactive logic, or sharing reactive state across your app.

documentation/docs/02-template-syntax/01-component-fundamentals.md renamed to documentation/docs/01-introduction/xx-props.md

+1-64
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,7 @@
11
---
2-
title: Component fundamentals
2+
title: Public API of a component
33
---
44

5-
- script (module) / template / style (rough overview)
6-
- `$props` / `$state` (in the context of components)
7-
8-
Components are the building blocks of Svelte applications. They are written into `.svelte` files, using a superset of HTML.
9-
10-
All three sections — script, styles and markup — are optional.
11-
12-
```svelte
13-
<script>
14-
// logic goes here
15-
</script>
16-
17-
<!-- markup (zero or more items) goes here -->
18-
19-
<style>
20-
/* styles go here */
21-
</style>
22-
```
23-
24-
## `<script>`
25-
26-
A `<script>` block contains JavaScript (or TypeScript, when adding the `lang="ts"` attribute) that runs when a component instance is created. Variables declared (or imported) at the top level are 'visible' from the component's markup.
27-
285
### Public API of a component
296

307
Svelte uses the `$props` rune to declare _properties_ or _props_, which means describing the public interface of the component which becomes accessible to consumers of the component.
@@ -160,43 +137,3 @@ If you'd like to react to changes to a prop, use the `$derived` or `$effect` run
160137
```
161138

162139
For more information on reactivity, read the documentation around runes.
163-
164-
## `<script module>`
165-
166-
A `<script>` tag with a `module` attribute runs once when the module first evaluates, rather than for each component instance. Values declared in this block are accessible from a regular `<script>` (and the component markup) but not vice versa.
167-
168-
You can `export` bindings from this block, and they will become exports of the compiled module.
169-
170-
You cannot `export default`, since the default export is the component itself.
171-
172-
```svelte
173-
<script module>
174-
let totalComponents = 0;
175-
176-
// the export keyword allows this function to imported with e.g.
177-
// `import Example, { alertTotal } from './Example.svelte'`
178-
export function alertTotal() {
179-
alert(totalComponents);
180-
}
181-
</script>
182-
183-
<script>
184-
totalComponents += 1;
185-
console.log(`total number of times this component has been created: ${totalComponents}`);
186-
</script>
187-
```
188-
189-
## `<style>`
190-
191-
CSS inside a `<style>` block will be scoped to that component.
192-
193-
```svelte
194-
<style>
195-
p {
196-
/* this will only affect <p> elements in this component */
197-
color: burlywood;
198-
}
199-
</style>
200-
```
201-
202-
For more information regarding styling, read the documentation around [styles and classes](styles-and-classes).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
title: What are runes?
3+
---
4+
5+
> [!NOTE] **rune** /ro͞on/ _noun_
6+
>
7+
> A letter or mark used as a mystical or magic symbol.
8+
9+
Runes are symbols that you use in `.svelte` and `.svelte.js`/`.svelte.ts` files to control the Svelte compiler. If you think of Svelte as a language, runes are part of the syntax — they are _keywords_.
10+
11+
Runes have a `$` prefix and look like functions:
12+
13+
```js
14+
let message = $state('hello');
15+
```
16+
17+
They differ from normal JavaScript functions in important ways, however:
18+
19+
- You don't need to import them — they are part of the language
20+
- They're not values — you can't assign them to a variable or pass them as arguments to a function
21+
- Just like JavaScript keywords, they are only valid in certain positions (the compiler will help you if you put them in the wrong place)

0 commit comments

Comments
 (0)