Skip to content

Commit 7b244aa

Browse files
committed
chore(examples): add Vite example using svelte v5
1 parent 9924c89 commit 7b244aa

File tree

10 files changed

+111
-0
lines changed

10 files changed

+111
-0
lines changed

examples/vite@svelte-5/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.DS_Store
2+
node_modules
3+
dist

examples/vite@svelte-5/README.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# examples/vite@svelte-5
2+
3+
> `svelte-highlight` Vite set-up.
4+
5+
## Available Scripts
6+
7+
### `bun dev`
8+
9+
Runs the project in development mode and watches for any changes.
10+
11+
### `bun run build`
12+
13+
Builds the project for production.
14+
15+
### `bun preview`
16+
17+
Preview the app locally. Run `bun run build` first.

examples/vite@svelte-5/bun.lockb

50.5 KB
Binary file not shown.

examples/vite@svelte-5/index.html

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
</head>
7+
<body>
8+
<script type="module">
9+
import { mount } from "svelte";
10+
import App from "./src/App.svelte";
11+
12+
mount(App, { target: document.body });
13+
</script>
14+
</body>
15+
</html>

examples/vite@svelte-5/package.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"private": true,
3+
"type": "module",
4+
"scripts": {
5+
"dev": "vite",
6+
"build": "vite build",
7+
"preview": "vite preview"
8+
},
9+
"devDependencies": {
10+
"@sveltejs/vite-plugin-svelte": "latest",
11+
"@tsconfig/svelte": "latest",
12+
"svelte": "5.0.0-next.200",
13+
"svelte-highlight": "latest",
14+
"typescript": "latest",
15+
"vite": "latest"
16+
}
17+
}

examples/vite@svelte-5/src/App.svelte

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<script lang="ts">
2+
import { Highlight } from "svelte-highlight";
3+
import typescript from "svelte-highlight/languages/typescript";
4+
import atomOneDark from "svelte-highlight/styles/atom-one-dark";
5+
import DynamicImport from "./DynamicImport.svelte";
6+
7+
const code = "const add = (a: number, b: number) => a + b;";
8+
</script>
9+
10+
<svelte:head>
11+
{@html atomOneDark}
12+
</svelte:head>
13+
14+
<Highlight language={typescript} {code} />
15+
16+
<DynamicImport />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<script lang="ts">
2+
import { onMount } from "svelte";
3+
import type { HighlightAuto } from "svelte-highlight";
4+
5+
let component: typeof HighlightAuto;
6+
let styles: string;
7+
8+
onMount(async () => {
9+
component = (await import("svelte-highlight")).HighlightAuto;
10+
styles = (await import("svelte-highlight/styles/atom-one-dark")).default;
11+
});
12+
</script>
13+
14+
<svelte:head>
15+
{#if styles}
16+
{@html styles}
17+
{/if}
18+
</svelte:head>
19+
20+
<svelte:component
21+
this={component}
22+
langtag
23+
code={`body {\n padding: 0;\n color: red;\n}`}
24+
/>
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/// <reference types="svelte" />
2+
/// <reference types="vite/client" />

examples/vite@svelte-5/tsconfig.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "@tsconfig/svelte/tsconfig.json",
3+
"compilerOptions": {
4+
"strict": true
5+
},
6+
"include": ["src/**/*.d.ts", "src/**/*.ts", "src/**/*.svelte"]
7+
}

examples/vite@svelte-5/vite.config.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { svelte, vitePreprocess } from "@sveltejs/vite-plugin-svelte";
2+
import type { UserConfig } from "vite";
3+
4+
export default {
5+
plugins: [
6+
svelte({
7+
preprocess: vitePreprocess(),
8+
}),
9+
],
10+
} satisfies UserConfig;

0 commit comments

Comments
 (0)