Spaces:
Running
Running
initial import
Browse files- .gitignore +24 -0
- .vscode/extensions.json +3 -0
- README.md +48 -2
- index.html +11 -17
- package.json +20 -0
- public/vite.svg +1 -0
- src/App.svelte +47 -0
- src/app.css +79 -0
- src/assets/svelte.svg +1 -0
- src/lib/Counter.svelte +10 -0
- src/main.ts +9 -0
- src/vite-env.d.ts +2 -0
- style.css +0 -28
- svelte.config.js +7 -0
- tsconfig.app.json +20 -0
- tsconfig.json +7 -0
- tsconfig.node.json +25 -0
- vite.config.ts +7 -0
.gitignore
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Logs
|
2 |
+
logs
|
3 |
+
*.log
|
4 |
+
npm-debug.log*
|
5 |
+
yarn-debug.log*
|
6 |
+
yarn-error.log*
|
7 |
+
pnpm-debug.log*
|
8 |
+
lerna-debug.log*
|
9 |
+
|
10 |
+
node_modules
|
11 |
+
dist
|
12 |
+
dist-ssr
|
13 |
+
*.local
|
14 |
+
|
15 |
+
# Editor directories and files
|
16 |
+
.vscode/*
|
17 |
+
!.vscode/extensions.json
|
18 |
+
.idea
|
19 |
+
.DS_Store
|
20 |
+
*.suo
|
21 |
+
*.ntvs*
|
22 |
+
*.njsproj
|
23 |
+
*.sln
|
24 |
+
*.sw?
|
.vscode/extensions.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"recommendations": ["svelte.svelte-vscode"]
|
3 |
+
}
|
README.md
CHANGED
@@ -1,10 +1,56 @@
|
|
1 |
---
|
2 |
title: Vite Svelte
|
3 |
emoji: 🐨
|
4 |
-
colorFrom:
|
5 |
colorTo: blue
|
6 |
sdk: static
|
7 |
pinned: false
|
8 |
---
|
9 |
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
title: Vite Svelte
|
3 |
emoji: 🐨
|
4 |
+
colorFrom: blue
|
5 |
colorTo: blue
|
6 |
sdk: static
|
7 |
pinned: false
|
8 |
---
|
9 |
|
10 |
+
# Svelte + TS + Vite
|
11 |
+
|
12 |
+
This template should help get you started developing with Svelte and TypeScript in Vite.
|
13 |
+
|
14 |
+
## Recommended IDE Setup
|
15 |
+
|
16 |
+
[VS Code](https://code.visualstudio.com/) + [Svelte](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode).
|
17 |
+
|
18 |
+
## Need an official Svelte framework?
|
19 |
+
|
20 |
+
Check out [SvelteKit](https://github.com/sveltejs/kit#readme), which is also powered by Vite. Deploy anywhere with its serverless-first approach and adapt to various platforms, with out of the box support for TypeScript, SCSS, and Less, and easily-added support for mdsvex, GraphQL, PostCSS, Tailwind CSS, and more.
|
21 |
+
|
22 |
+
## Technical considerations
|
23 |
+
|
24 |
+
**Why use this over SvelteKit?**
|
25 |
+
|
26 |
+
- It brings its own routing solution which might not be preferable for some users.
|
27 |
+
- It is first and foremost a framework that just happens to use Vite under the hood, not a Vite app.
|
28 |
+
|
29 |
+
This template contains as little as possible to get started with Vite + TypeScript + Svelte, while taking into account the developer experience with regards to HMR and intellisense. It demonstrates capabilities on par with the other `create-vite` templates and is a good starting point for beginners dipping their toes into a Vite + Svelte project.
|
30 |
+
|
31 |
+
Should you later need the extended capabilities and extensibility provided by SvelteKit, the template has been structured similarly to SvelteKit so that it is easy to migrate.
|
32 |
+
|
33 |
+
**Why `global.d.ts` instead of `compilerOptions.types` inside `jsconfig.json` or `tsconfig.json`?**
|
34 |
+
|
35 |
+
Setting `compilerOptions.types` shuts out all other types not explicitly listed in the configuration. Using triple-slash references keeps the default TypeScript setting of accepting type information from the entire workspace, while also adding `svelte` and `vite/client` type information.
|
36 |
+
|
37 |
+
**Why include `.vscode/extensions.json`?**
|
38 |
+
|
39 |
+
Other templates indirectly recommend extensions via the README, but this file allows VS Code to prompt the user to install the recommended extension upon opening the project.
|
40 |
+
|
41 |
+
**Why enable `allowJs` in the TS template?**
|
42 |
+
|
43 |
+
While `allowJs: false` would indeed prevent the use of `.js` files in the project, it does not prevent the use of JavaScript syntax in `.svelte` files. In addition, it would force `checkJs: false`, bringing the worst of both worlds: not being able to guarantee the entire codebase is TypeScript, and also having worse typechecking for the existing JavaScript. In addition, there are valid use cases in which a mixed codebase may be relevant.
|
44 |
+
|
45 |
+
**Why is HMR not preserving my local component state?**
|
46 |
+
|
47 |
+
HMR state preservation comes with a number of gotchas! It has been disabled by default in both `svelte-hmr` and `@sveltejs/vite-plugin-svelte` due to its often surprising behavior. You can read the details [here](https://github.com/rixo/svelte-hmr#svelte-hmr).
|
48 |
+
|
49 |
+
If you have state that's important to retain within a component, consider creating an external store which would not be replaced by HMR.
|
50 |
+
|
51 |
+
```ts
|
52 |
+
// store.ts
|
53 |
+
// An extremely simple external store
|
54 |
+
import { writable } from 'svelte/store'
|
55 |
+
export default writable(0)
|
56 |
+
```
|
index.html
CHANGED
@@ -1,19 +1,13 @@
|
|
1 |
<!doctype html>
|
2 |
-
<html>
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
<p>
|
14 |
-
Also don't forget to check the
|
15 |
-
<a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
|
16 |
-
</p>
|
17 |
-
</div>
|
18 |
-
</body>
|
19 |
</html>
|
|
|
1 |
<!doctype html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8" />
|
5 |
+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
7 |
+
<title>Vite + Svelte + TS</title>
|
8 |
+
</head>
|
9 |
+
<body>
|
10 |
+
<div id="app"></div>
|
11 |
+
<script type="module" src="/src/main.ts"></script>
|
12 |
+
</body>
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
</html>
|
package.json
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "vite-svelte",
|
3 |
+
"private": true,
|
4 |
+
"version": "0.0.0",
|
5 |
+
"type": "module",
|
6 |
+
"scripts": {
|
7 |
+
"dev": "vite",
|
8 |
+
"build": "vite build",
|
9 |
+
"preview": "vite preview",
|
10 |
+
"check": "svelte-check --tsconfig ./tsconfig.app.json && tsc -p tsconfig.node.json"
|
11 |
+
},
|
12 |
+
"devDependencies": {
|
13 |
+
"@sveltejs/vite-plugin-svelte": "^5.0.3",
|
14 |
+
"@tsconfig/svelte": "^5.0.4",
|
15 |
+
"svelte": "^5.28.1",
|
16 |
+
"svelte-check": "^4.1.6",
|
17 |
+
"typescript": "~5.8.3",
|
18 |
+
"vite": "^6.3.5"
|
19 |
+
}
|
20 |
+
}
|
public/vite.svg
ADDED
|
src/App.svelte
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<script lang="ts">
|
2 |
+
import svelteLogo from './assets/svelte.svg'
|
3 |
+
import viteLogo from '/vite.svg'
|
4 |
+
import Counter from './lib/Counter.svelte'
|
5 |
+
</script>
|
6 |
+
|
7 |
+
<main>
|
8 |
+
<div>
|
9 |
+
<a href="https://vite.dev" target="_blank" rel="noreferrer">
|
10 |
+
<img src={viteLogo} class="logo" alt="Vite Logo" />
|
11 |
+
</a>
|
12 |
+
<a href="https://svelte.dev" target="_blank" rel="noreferrer">
|
13 |
+
<img src={svelteLogo} class="logo svelte" alt="Svelte Logo" />
|
14 |
+
</a>
|
15 |
+
</div>
|
16 |
+
<h1>Vite + Svelte</h1>
|
17 |
+
|
18 |
+
<div class="card">
|
19 |
+
<Counter />
|
20 |
+
</div>
|
21 |
+
|
22 |
+
<p>
|
23 |
+
Check out <a href="https://github.com/sveltejs/kit#readme" target="_blank" rel="noreferrer">SvelteKit</a>, the official Svelte app framework powered by Vite!
|
24 |
+
</p>
|
25 |
+
|
26 |
+
<p class="read-the-docs">
|
27 |
+
Click on the Vite and Svelte logos to learn more
|
28 |
+
</p>
|
29 |
+
</main>
|
30 |
+
|
31 |
+
<style>
|
32 |
+
.logo {
|
33 |
+
height: 6em;
|
34 |
+
padding: 1.5em;
|
35 |
+
will-change: filter;
|
36 |
+
transition: filter 300ms;
|
37 |
+
}
|
38 |
+
.logo:hover {
|
39 |
+
filter: drop-shadow(0 0 2em #646cffaa);
|
40 |
+
}
|
41 |
+
.logo.svelte:hover {
|
42 |
+
filter: drop-shadow(0 0 2em #ff3e00aa);
|
43 |
+
}
|
44 |
+
.read-the-docs {
|
45 |
+
color: #888;
|
46 |
+
}
|
47 |
+
</style>
|
src/app.css
ADDED
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
:root {
|
2 |
+
font-family: system-ui, Avenir, Helvetica, Arial, sans-serif;
|
3 |
+
line-height: 1.5;
|
4 |
+
font-weight: 400;
|
5 |
+
|
6 |
+
color-scheme: light dark;
|
7 |
+
color: rgba(255, 255, 255, 0.87);
|
8 |
+
background-color: #242424;
|
9 |
+
|
10 |
+
font-synthesis: none;
|
11 |
+
text-rendering: optimizeLegibility;
|
12 |
+
-webkit-font-smoothing: antialiased;
|
13 |
+
-moz-osx-font-smoothing: grayscale;
|
14 |
+
}
|
15 |
+
|
16 |
+
a {
|
17 |
+
font-weight: 500;
|
18 |
+
color: #646cff;
|
19 |
+
text-decoration: inherit;
|
20 |
+
}
|
21 |
+
a:hover {
|
22 |
+
color: #535bf2;
|
23 |
+
}
|
24 |
+
|
25 |
+
body {
|
26 |
+
margin: 0;
|
27 |
+
display: flex;
|
28 |
+
place-items: center;
|
29 |
+
min-width: 320px;
|
30 |
+
min-height: 100vh;
|
31 |
+
}
|
32 |
+
|
33 |
+
h1 {
|
34 |
+
font-size: 3.2em;
|
35 |
+
line-height: 1.1;
|
36 |
+
}
|
37 |
+
|
38 |
+
.card {
|
39 |
+
padding: 2em;
|
40 |
+
}
|
41 |
+
|
42 |
+
#app {
|
43 |
+
max-width: 1280px;
|
44 |
+
margin: 0 auto;
|
45 |
+
padding: 2rem;
|
46 |
+
text-align: center;
|
47 |
+
}
|
48 |
+
|
49 |
+
button {
|
50 |
+
border-radius: 8px;
|
51 |
+
border: 1px solid transparent;
|
52 |
+
padding: 0.6em 1.2em;
|
53 |
+
font-size: 1em;
|
54 |
+
font-weight: 500;
|
55 |
+
font-family: inherit;
|
56 |
+
background-color: #1a1a1a;
|
57 |
+
cursor: pointer;
|
58 |
+
transition: border-color 0.25s;
|
59 |
+
}
|
60 |
+
button:hover {
|
61 |
+
border-color: #646cff;
|
62 |
+
}
|
63 |
+
button:focus,
|
64 |
+
button:focus-visible {
|
65 |
+
outline: 4px auto -webkit-focus-ring-color;
|
66 |
+
}
|
67 |
+
|
68 |
+
@media (prefers-color-scheme: light) {
|
69 |
+
:root {
|
70 |
+
color: #213547;
|
71 |
+
background-color: #ffffff;
|
72 |
+
}
|
73 |
+
a:hover {
|
74 |
+
color: #747bff;
|
75 |
+
}
|
76 |
+
button {
|
77 |
+
background-color: #f9f9f9;
|
78 |
+
}
|
79 |
+
}
|
src/assets/svelte.svg
ADDED
|
src/lib/Counter.svelte
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<script lang="ts">
|
2 |
+
let count: number = $state(0)
|
3 |
+
const increment = () => {
|
4 |
+
count += 1
|
5 |
+
}
|
6 |
+
</script>
|
7 |
+
|
8 |
+
<button onclick={increment}>
|
9 |
+
count is {count}
|
10 |
+
</button>
|
src/main.ts
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { mount } from 'svelte'
|
2 |
+
import './app.css'
|
3 |
+
import App from './App.svelte'
|
4 |
+
|
5 |
+
const app = mount(App, {
|
6 |
+
target: document.getElementById('app')!,
|
7 |
+
})
|
8 |
+
|
9 |
+
export default app
|
src/vite-env.d.ts
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
/// <reference types="svelte" />
|
2 |
+
/// <reference types="vite/client" />
|
style.css
DELETED
@@ -1,28 +0,0 @@
|
|
1 |
-
body {
|
2 |
-
padding: 2rem;
|
3 |
-
font-family: -apple-system, BlinkMacSystemFont, "Arial", sans-serif;
|
4 |
-
}
|
5 |
-
|
6 |
-
h1 {
|
7 |
-
font-size: 16px;
|
8 |
-
margin-top: 0;
|
9 |
-
}
|
10 |
-
|
11 |
-
p {
|
12 |
-
color: rgb(107, 114, 128);
|
13 |
-
font-size: 15px;
|
14 |
-
margin-bottom: 10px;
|
15 |
-
margin-top: 5px;
|
16 |
-
}
|
17 |
-
|
18 |
-
.card {
|
19 |
-
max-width: 620px;
|
20 |
-
margin: 0 auto;
|
21 |
-
padding: 16px;
|
22 |
-
border: 1px solid lightgray;
|
23 |
-
border-radius: 16px;
|
24 |
-
}
|
25 |
-
|
26 |
-
.card p:last-child {
|
27 |
-
margin-bottom: 0;
|
28 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
svelte.config.js
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'
|
2 |
+
|
3 |
+
export default {
|
4 |
+
// Consult https://svelte.dev/docs#compile-time-svelte-preprocess
|
5 |
+
// for more information about preprocessors
|
6 |
+
preprocess: vitePreprocess(),
|
7 |
+
}
|
tsconfig.app.json
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"extends": "@tsconfig/svelte/tsconfig.json",
|
3 |
+
"compilerOptions": {
|
4 |
+
"target": "ESNext",
|
5 |
+
"useDefineForClassFields": true,
|
6 |
+
"module": "ESNext",
|
7 |
+
"resolveJsonModule": true,
|
8 |
+
/**
|
9 |
+
* Typecheck JS in `.svelte` and `.js` files by default.
|
10 |
+
* Disable checkJs if you'd like to use dynamic types in JS.
|
11 |
+
* Note that setting allowJs false does not prevent the use
|
12 |
+
* of JS in `.svelte` files.
|
13 |
+
*/
|
14 |
+
"allowJs": true,
|
15 |
+
"checkJs": true,
|
16 |
+
"isolatedModules": true,
|
17 |
+
"moduleDetection": "force"
|
18 |
+
},
|
19 |
+
"include": ["src/**/*.ts", "src/**/*.js", "src/**/*.svelte"]
|
20 |
+
}
|
tsconfig.json
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"files": [],
|
3 |
+
"references": [
|
4 |
+
{ "path": "./tsconfig.app.json" },
|
5 |
+
{ "path": "./tsconfig.node.json" }
|
6 |
+
]
|
7 |
+
}
|
tsconfig.node.json
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"compilerOptions": {
|
3 |
+
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
4 |
+
"target": "ES2022",
|
5 |
+
"lib": ["ES2023"],
|
6 |
+
"module": "ESNext",
|
7 |
+
"skipLibCheck": true,
|
8 |
+
|
9 |
+
/* Bundler mode */
|
10 |
+
"moduleResolution": "bundler",
|
11 |
+
"allowImportingTsExtensions": true,
|
12 |
+
"verbatimModuleSyntax": true,
|
13 |
+
"moduleDetection": "force",
|
14 |
+
"noEmit": true,
|
15 |
+
|
16 |
+
/* Linting */
|
17 |
+
"strict": true,
|
18 |
+
"noUnusedLocals": true,
|
19 |
+
"noUnusedParameters": true,
|
20 |
+
"erasableSyntaxOnly": true,
|
21 |
+
"noFallthroughCasesInSwitch": true,
|
22 |
+
"noUncheckedSideEffectImports": true
|
23 |
+
},
|
24 |
+
"include": ["vite.config.ts"]
|
25 |
+
}
|
vite.config.ts
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { defineConfig } from 'vite'
|
2 |
+
import { svelte } from '@sveltejs/vite-plugin-svelte'
|
3 |
+
|
4 |
+
// https://vite.dev/config/
|
5 |
+
export default defineConfig({
|
6 |
+
plugins: [svelte()],
|
7 |
+
})
|