Skip to content

Commit 70bf98d

Browse files
feat: use rollup web worker for Svelte tutorial (#207)
* feat: use rollup web worker for Svelte tutorial * drive by warnings fix for webcontainer * stores -> runes for adapter state in order to better combine them; most usage locations untouched deliberately (they can be adjusted later on) * js -> ts * make sure loading screen shows up at the right times * integrate REPL console into Svelte tutorial * tidy up * implement refresh for rollup build * warning fixes * adjust tutorial assets + remove global styles as they pollute other chapters * apply tutorial styles to Svelte tutorials * tweak headers * like this? * relaxed * server tutorial assets through our own proxy due to header conflicts * enable cross origin headers for all resources * use crossorigin attribute instead of proxy * document this shit * prettier * don't set headers here, happens on Vercel edge + dev middleware * fix * add attributes to get third party links working again * fix * make it possible use relative svg files by adjusting bundler to use base64 version of them * support mp3 imports * use same approach for images aswell * remove unused files * more detail about cross-origin isolation etc * bring asset handling section up to date * add some equivalent tooltip styles to the original * automate cross-origin isolation * oops * fix * remove old styles on unmount; bring back global styles * revert margin change, no longer relevant * the lettering is something called Silian Rail --------- Co-authored-by: Rich Harris <rich.harris@vercel.com>
1 parent 50037a8 commit 70bf98d

File tree

85 files changed

+1429
-893
lines changed

Some content is hidden

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

85 files changed

+1429
-893
lines changed

apps/svelte.dev/README.md

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,25 @@
1-
# create-svelte
1+
# svelte.dev
22

3-
Everything you need to build a Svelte project, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/main/packages/create-svelte).
3+
This is the app behind [svelte.dev](https://svelte.dev), the official Svelte site.
44

5-
## Creating a project
5+
## Development
66

7-
If you're seeing this, you've probably already done this step. Congrats!
7+
### Tutorial
88

9-
```bash
10-
# create a new project in the current directory
11-
npx sv create
9+
The tutorial consists of two technically different parts: The Svelte tutorial and the SvelteKit tutorial. The SvelteKit tutorial uses [WebContainers](https://webcontainers.io/) under the hood in order to boot up a Node runtime in the browser. The Svelte tutorial uses Rollup in a web worker - it does not use WebContainers because a simple web worker is both faster and more reliable (there are known issues with iOS mobile).
1210

13-
# create a new project in my-app
14-
npx sv create my-app
15-
```
16-
17-
## Developing
18-
19-
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
20-
21-
```bash
22-
npm run dev
11+
WebContainers require [cross-origin isolation](https://webcontainers.io/guides/quickstart#cross-origin-isolation), which means the document needs to have these headers:
2312

24-
# or start the server and open the app in a new browser tab
25-
npm run dev -- --open
13+
```
14+
Cross-Origin-Embedder-Policy: require-corp
15+
Cross-Origin-Opener-Policy: same-origin
2616
```
2717

28-
## Building
29-
30-
To create a production version of your app:
18+
Because we're doing soft navigation between pages, these headers need to be set for all responses, not just the ones from `/tutorial`.
3119

32-
```bash
33-
npm run build
34-
```
20+
The result of setting these headers is that the site can no longer embed URLs from other sites (like images from another domain) without those domains either having a `cross-origin-resource-policy: cross-origin` header (which most don't) or us adding the `crossorigin="anonymous"` attribute to the elements that load those URLs.
3521

36-
You can preview the production build with `npm run preview`.
22+
When writing content for the tutorial, you need to be aware of the differences of loading content:
3723

38-
> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
24+
- When using root-relative paths, for a SvelteKit exercise the 'root' is the `static` directory inside the exercise itself, but for a Svelte exercise it is the root of the app so assets should do inside `apps/svelte.dev/static/tutorial`.
25+
- When importing relative assets in a Svelte exercise, Rollup inlines them into the bundle as base64

apps/svelte.dev/content/blog/2019-01-31-svelte-on-the-changelog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ Unless you hang out in our [Discord server](https://svelte.dev/chat) or follow [
1818

1919
On the podcast [Adam](https://twitter.com/adamstac), [Jerod](https://twitter.com/jerodsanto) and I talk about some of the changes and why we're making them. You can listen here or on the [podcast page](https://changelog.com/podcast/332).
2020

21-
<audio data-theme="night" style="width: 100%" data-src="https://changelog.com/podcast/332/embed" src="https://cdn.changelog.com/uploads/podcast/332/the-changelog-332.mp3" preload="none" class="changelog-episode" controls></audio><p><a href="https://changelog.com/podcast/332">The Changelog 332: A UI framework without the framework</a> – Listen on <a href="https://changelog.com/">Changelog.com</a></p><script async src="//cdn.changelog.com/embed.js"></script>
21+
<audio crossorigin="anonymous" data-theme="night" style="width: 100%" data-src="https://changelog.com/podcast/332/embed" src="https://cdn.changelog.com/uploads/podcast/332/the-changelog-332.mp3" preload="none" class="changelog-episode" controls></audio><p><a href="https://changelog.com/podcast/332">The Changelog 332: A UI framework without the framework</a> – Listen on <a href="https://changelog.com/">Changelog.com</a></p><script async src="//cdn.changelog.com/embed.js"></script>

apps/svelte.dev/content/blog/2019-04-22-svelte-3-rethinking-reactivity.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ To make that possible we first needed to rethink the concept at the heart of mod
2424
<div class="max">
2525
<figure style="max-width: 960px; margin: 0 auto">
2626
<div style="height: 0; padding: 0 0 57.1% 0; position: relative; margin: 0 auto;">
27-
<iframe style="position: absolute; width: 100%; height: 100%; left: 0; top: 0; margin: 0;" src="https://www.youtube-nocookie.com/embed/AdNJ3fydeao" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
27+
<iframe credentialless style="position: absolute; width: 100%; height: 100%; left: 0; top: 0; margin: 0;" src="https://www.youtube-nocookie.com/embed/AdNJ3fydeao" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
2828
</div>
2929

3030
<figcaption>'Rethinking Reactivity' from <a href="https://www.israel.yglfconf.com/">You Gotta Love Frontend Code Camp</a></figcaption>

apps/svelte.dev/content/blog/2020-11-05-whats-the-deal-with-sveltekit.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ This was slightly tongue-in-cheek — as the talk explains, it's really more of
1616
<div class="max">
1717
<figure style="max-width: 960px; margin: 0 auto">
1818
<div style="height: 0; padding: 0 0 57.1% 0; position: relative; margin: 0 auto;">
19-
<iframe style="position: absolute; width: 100%; height: 100%; left: 0; top: 0; margin: 0;" src="https://www.youtube-nocookie.com/embed/qSfdtmcZ4d0" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
19+
<iframe credentialless style="position: absolute; width: 100%; height: 100%; left: 0; top: 0; margin: 0;" src="https://www.youtube-nocookie.com/embed/qSfdtmcZ4d0" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
2020
</div>
2121

2222
<figcaption>'Futuristic Web Development' from <a href="https://sveltesummit.com/">Svelte Summit</a></figcaption>

apps/svelte.dev/content/blog/2022-12-14-announcing-sveltekit-1.0.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ To get started, run `npm create svelte@latest`, and visit the [docs](https://kit
1414
<div class="max">
1515
<figure style="max-width: 960px; margin: 0 auto">
1616
<div style="height: 0; padding: 0 0 57.1% 0; position: relative; margin: 0 auto;">
17-
<iframe style="position: absolute; width: 100%; height: 100%; left: 0; top: 0; margin: 0;" src="https://www.youtube-nocookie.com/embed/N4BRVkQVoMc" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
17+
<iframe credentialless style="position: absolute; width: 100%; height: 100%; left: 0; top: 0; margin: 0;" src="https://www.youtube-nocookie.com/embed/N4BRVkQVoMc" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
1818
</div>
1919

2020
<figcaption>Svelte Radio Live: the Christmas special</figcaption>

apps/svelte.dev/content/blog/2023-03-09-zero-config-type-safety.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ But what if we didn't even need the annotations? Since `load` and `data` are par
1111

1212
As of today, yes: it can.
1313

14-
<video src="https://sveltejs.github.io/assets/video/zero-config-types.mp4" controls muted playsinline></video>
14+
<video crossorigin="anonymous" src="https://sveltejs.github.io/assets/video/zero-config-types.mp4" controls muted playsinline></video>
1515

1616
If you're using VSCode, just upgrade the Svelte extension to the latest version, and you'll never have to annotate your `load` functions or `data` props again. Extensions for other editors can also use this feature, as long as they support the Language Server Protocol and TypeScript plugins. It even works with the latest version of our CLI diagnostics tool `svelte-check`!
1717

apps/svelte.dev/content/blog/2023-08-31-view-transitions.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ onNavigate((navigation) => {
7474

7575
With that, every navigation that occurs will trigger a view transition. You can already see this in action – by default, the browser will crossfade between the old and new pages.
7676

77-
<video src="https://sveltejs.github.io/assets/video/vt-demo-1.mp4" controls muted playsinline></video>
77+
<video crossorigin="anonymous" src="https://sveltejs.github.io/assets/video/vt-demo-1.mp4" controls muted playsinline></video>
7878

7979
<details>
8080
<summary>How the code works</summary>
@@ -161,7 +161,7 @@ header {
161161

162162
Now, the header will not transition in and out on navigation, but the rest of the page will.
163163

164-
<video src="https://sveltejs.github.io/assets/video/vt-demo-2.mp4" controls muted playsinline></video>
164+
<video crossorigin="anonymous" src="https://sveltejs.github.io/assets/video/vt-demo-2.mp4" controls muted playsinline></video>
165165

166166
<details>
167167
<summary>Fixing the types</summary>
@@ -213,7 +213,7 @@ li[aria-current='page']::before {
213213

214214
By adding that single line, the indicator will now smoothly slide to its new position instead of jumping.
215215

216-
<video src="https://sveltejs.github.io/assets/video/vt-demo-3.mp4" controls muted playsinline></video>
216+
<video crossorigin="anonymous" src="https://sveltejs.github.io/assets/video/vt-demo-3.mp4" controls muted playsinline></video>
217217

218218
(It might be easy to miss the difference – look at the small moving triangle indicator at the top of the screen!)
219219

apps/svelte.dev/content/tutorial/+assets/src/app.html

Lines changed: 2 additions & 252 deletions
Original file line numberDiff line numberDiff line change
@@ -7,258 +7,8 @@
77
<meta name="color-scheme" content="dark light" />
88
%sveltekit.head%
99

10-
<style>
11-
html {
12-
--bg-1: hsl(0, 0%, 100%);
13-
--bg-2: hsl(206, 20%, 90%);
14-
--bg-3: hsl(206, 20%, 80%);
15-
--fg-1: hsl(0, 0%, 13%);
16-
--fg-2: hsl(0, 0%, 20%);
17-
--fg-2: hsl(0, 0%, 30%);
18-
--link: hsl(208, 77%, 47%);
19-
--link-hover: hsl(208, 77%, 55%);
20-
--link-active: hsl(208, 77%, 40%);
21-
22-
&.dark {
23-
--bg-1: hsl(0, 0%, 18%);
24-
--bg-2: hsl(0, 0%, 30%);
25-
--bg-3: hsl(0, 0%, 40%);
26-
--fg-1: hsl(0, 0%, 90%);
27-
--fg-2: hsl(0, 0%, 70%);
28-
--fg-3: hsl(0, 0%, 60%);
29-
--link: hsl(206, 96%, 72%);
30-
--link-hover: hsl(206, 96%, 78%);
31-
--link-active: hsl(206, 96%, 64%);
32-
}
33-
}
34-
35-
body {
36-
--border-radius: 4px;
37-
--font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell,
38-
'Open Sans', 'Helvetica Neue', sans-serif;
39-
--font-mono: ui-monospace, 'Cascadia Code', 'Source Code Pro', Menlo, Consolas,
40-
'DejaVu Sans Mono', monospace;
41-
background: var(--bg-1);
42-
color: var(--fg-1);
43-
font-family: var(--font);
44-
line-height: 1.5;
45-
margin: 1rem;
46-
height: calc(100vh - 2rem);
47-
}
48-
49-
h1,
50-
h2,
51-
h3,
52-
h4,
53-
h5,
54-
h6 {
55-
font-weight: normal;
56-
font-variant-numeric: tabular-nums;
57-
line-height: 1.1;
58-
}
59-
60-
:is(h1, h2, h3, h4, h5, h6, p) {
61-
margin: 1rem 0.1rem;
62-
}
63-
64-
label {
65-
margin: 0.5rem 0.1rem;
66-
}
67-
68-
:is(h1, h2, h3, h4, h5, h6, p, label):first-child {
69-
margin-top: 0;
70-
}
71-
72-
:is(h1, h2, h3, h4, h5, h6, p, label):last-child {
73-
margin-bottom: 0;
74-
}
75-
76-
a {
77-
color: var(--link);
78-
}
79-
80-
a:hover {
81-
color: var(--link-hover);
82-
}
83-
84-
a:active {
85-
color: var(--link-active);
86-
}
87-
88-
label {
89-
display: flex;
90-
gap: 0.5rem;
91-
align-items: center;
92-
}
93-
94-
label input {
95-
margin: 0;
96-
}
97-
98-
button,
99-
input,
100-
select {
101-
font-family: inherit;
102-
font-size: inherit;
103-
}
104-
105-
button {
106-
background: var(--link);
107-
color: var(--bg-1);
108-
padding: 0.5rem 1rem;
109-
border: none;
110-
border-radius: var(--border-radius);
111-
}
112-
113-
button:hover {
114-
background: var(--link-hover);
115-
}
116-
117-
button:active {
118-
background: var(--link-active);
119-
}
120-
121-
:is(button, button:hover, button:active):disabled {
122-
background: var(--link);
123-
filter: grayscale(1);
124-
opacity: 0.4;
125-
}
126-
127-
input,
128-
textarea,
129-
select {
130-
padding: 0.5rem;
131-
border: 1px solid var(--bg-2);
132-
border-radius: var(--border-radius);
133-
box-sizing: border-box;
134-
}
135-
136-
input,
137-
textarea {
138-
background: var(--bg-1);
139-
color: inherit;
140-
}
141-
142-
select:not([multiple]) {
143-
background: var(--bg-2);
144-
}
145-
146-
textarea {
147-
font-family: var(--font-mono);
148-
font-size: 0.9rem;
149-
}
150-
151-
form {
152-
display: flex;
153-
flex-direction: column;
154-
gap: 1rem;
155-
align-items: baseline;
156-
}
157-
158-
ul:has(li):has(form) {
159-
list-style: none;
160-
padding: 0;
161-
}
162-
163-
li form {
164-
flex-direction: row;
165-
gap: 0.5rem;
166-
margin: 0.5rem 0;
167-
}
168-
169-
nav {
170-
position: relative;
171-
display: flex;
172-
gap: 1em;
173-
padding: 1em;
174-
background: var(--bg-2);
175-
z-index: 2;
176-
margin: 0 0 1em 0;
177-
border-radius: var(--border-radius);
178-
}
179-
180-
nav a {
181-
text-decoration: none;
182-
}
183-
184-
nav a[aria-current='true'] {
185-
border-bottom: 2px solid;
186-
}
187-
188-
ul:has(form) {
189-
list-style: none;
190-
padding: 0;
191-
}
192-
193-
progress {
194-
margin: 0.5rem 0;
195-
}
196-
197-
progress:first-child {
198-
margin-top: 0;
199-
}
200-
201-
progress:lsat-child {
202-
margin-bottom: 0;
203-
}
204-
205-
.error {
206-
color: red;
207-
}
208-
209-
code {
210-
background: var(--bg-2);
211-
font-family: var(--font-mono);
212-
font-size: 0.9em;
213-
padding: 0.15rem 0.3rem;
214-
border-radius: var(--border-radius);
215-
}
216-
217-
ul.todos {
218-
padding: 0;
219-
}
220-
221-
ul.todos li:not(:has(> form)),
222-
ul.todos li form {
223-
position: relative;
224-
display: flex;
225-
align-items: center;
226-
padding: 0.5em 0.5em 0.5em 1em;
227-
margin: 0 0 0.5em 0;
228-
gap: 0.5em;
229-
border-radius: 5px;
230-
user-select: none;
231-
background: var(--bg-1);
232-
filter: drop-shadow(2px 3px 6px rgba(0, 0, 0, 0.1));
233-
transition:
234-
filter 0.2s,
235-
opacity 0.2s;
236-
}
237-
238-
ul.todos .done {
239-
filter: none;
240-
opacity: 0.4;
241-
}
242-
243-
ul.todos button {
244-
border: none;
245-
background-color: transparent;
246-
background-repeat: no-repeat;
247-
background-position: 50% 50%;
248-
background-size: 1rem 1rem;
249-
cursor: pointer;
250-
width: 3em;
251-
height: 3em;
252-
margin: -0.5em -0.5em -0.5em 0;
253-
aspect-ratio: 1;
254-
opacity: 0.5;
255-
transition: opacity 0.2s;
256-
}
257-
258-
ul.todos button:hover {
259-
opacity: 1;
260-
}
261-
</style>
10+
<!-- duplication with svelte.dev/static/shared.css needed, else styles aren't applied during local dev -->
11+
<link rel="stylesheet" href="/shared.css" />
26212
</head>
26313
<body>
26414
<div style="display: contents">%sveltekit.body%</div>

0 commit comments

Comments
 (0)