Skip to content

Commit

Permalink
chore(examples): add Vite example using svelte v5
Browse files Browse the repository at this point in the history
  • Loading branch information
metonym committed Jul 27, 2024
1 parent 3746205 commit ac9848a
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/vite@svelte-5/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_Store
node_modules
dist
17 changes: 17 additions & 0 deletions examples/vite@svelte-5/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# examples/vite@svelte-5

> `svelte-highlight` Vite set-up.
## Available Scripts

### `bun dev`

Runs the project in development mode and watches for any changes.

### `bun run build`

Builds the project for production.

### `bun preview`

Preview the app locally. Run `bun run build` first.
Binary file added examples/vite@svelte-5/bun.lockb
Binary file not shown.
15 changes: 15 additions & 0 deletions examples/vite@svelte-5/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<script type="module">
import { mount } from "svelte";
import App from "./src/App.svelte";

mount(App, { target: document.body });
</script>
</body>
</html>
17 changes: 17 additions & 0 deletions examples/vite@svelte-5/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "latest",
"@tsconfig/svelte": "latest",
"svelte": "5.0.0-next.200",
"svelte-highlight": "latest",
"typescript": "latest",
"vite": "latest"
}
}
16 changes: 16 additions & 0 deletions examples/vite@svelte-5/src/App.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<script lang="ts">
import { Highlight } from "svelte-highlight";
import typescript from "svelte-highlight/languages/typescript";
import atomOneDark from "svelte-highlight/styles/atom-one-dark";
import DynamicImport from "./DynamicImport.svelte";
const code = "const add = (a: number, b: number) => a + b;";
</script>

<svelte:head>
{@html atomOneDark}
</svelte:head>

<Highlight language={typescript} {code} />

<DynamicImport />
24 changes: 24 additions & 0 deletions examples/vite@svelte-5/src/DynamicImport.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<script lang="ts">
import { onMount } from "svelte";
import type { HighlightAuto } from "svelte-highlight";
let component: typeof HighlightAuto;
let styles: string;
onMount(async () => {
component = (await import("svelte-highlight")).HighlightAuto;
styles = (await import("svelte-highlight/styles/atom-one-dark")).default;
});
</script>

<svelte:head>
{#if styles}
{@html styles}
{/if}
</svelte:head>

<svelte:component
this={component}
langtag
code={`body {\n padding: 0;\n color: red;\n}`}
/>
2 changes: 2 additions & 0 deletions examples/vite@svelte-5/src/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// <reference types="svelte" />
/// <reference types="vite/client" />
7 changes: 7 additions & 0 deletions examples/vite@svelte-5/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "@tsconfig/svelte/tsconfig.json",
"compilerOptions": {
"strict": true
},
"include": ["src/**/*.d.ts", "src/**/*.ts", "src/**/*.svelte"]
}
10 changes: 10 additions & 0 deletions examples/vite@svelte-5/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { svelte, vitePreprocess } from "@sveltejs/vite-plugin-svelte";
import type { UserConfig } from "vite";

export default {
plugins: [
svelte({
preprocess: vitePreprocess(),
}),
],
} satisfies UserConfig;

0 comments on commit ac9848a

Please sign in to comment.