create-vite-extra 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +79 -0
- package/index.js +384 -0
- package/package.json +34 -0
- package/template-library/_gitignore +24 -0
- package/template-library/index.d.ts +1 -0
- package/template-library/index.html +13 -0
- package/template-library/javascript.svg +1 -0
- package/template-library/lib/main.js +9 -0
- package/template-library/main.js +23 -0
- package/template-library/package.json +22 -0
- package/template-library/public/vite.svg +1 -0
- package/template-library/style.css +97 -0
- package/template-library/vite.config.js +11 -0
- package/template-library-ts/_gitignore +24 -0
- package/template-library-ts/index.d.ts +1 -0
- package/template-library-ts/index.html +13 -0
- package/template-library-ts/lib/main.ts +9 -0
- package/template-library-ts/package.json +23 -0
- package/template-library-ts/public/vite.svg +1 -0
- package/template-library-ts/src/main.ts +23 -0
- package/template-library-ts/src/style.css +97 -0
- package/template-library-ts/src/typescript.svg +1 -0
- package/template-library-ts/src/vite-env.d.ts +1 -0
- package/template-library-ts/tsconfig.json +20 -0
- package/template-library-ts/vite.config.ts +11 -0
- package/template-ssr-preact/_gitignore +24 -0
- package/template-ssr-preact/index.html +14 -0
- package/template-ssr-preact/package.json +25 -0
- package/template-ssr-preact/public/vite.svg +1 -0
- package/template-ssr-preact/server.js +71 -0
- package/template-ssr-preact/src/app.css +25 -0
- package/template-ssr-preact/src/app.jsx +32 -0
- package/template-ssr-preact/src/assets/preact.svg +1 -0
- package/template-ssr-preact/src/entry-client.jsx +5 -0
- package/template-ssr-preact/src/entry-server.jsx +7 -0
- package/template-ssr-preact/src/index.css +70 -0
- package/template-ssr-preact/vite.config.js +15 -0
- package/template-ssr-preact-ts/_gitignore +24 -0
- package/template-ssr-preact-ts/index.html +14 -0
- package/template-ssr-preact-ts/package.json +27 -0
- package/template-ssr-preact-ts/public/vite.svg +1 -0
- package/template-ssr-preact-ts/server.js +71 -0
- package/template-ssr-preact-ts/src/app.css +25 -0
- package/template-ssr-preact-ts/src/app.tsx +32 -0
- package/template-ssr-preact-ts/src/assets/preact.svg +1 -0
- package/template-ssr-preact-ts/src/entry-client.tsx +5 -0
- package/template-ssr-preact-ts/src/entry-server.tsx +7 -0
- package/template-ssr-preact-ts/src/index.css +70 -0
- package/template-ssr-preact-ts/src/preact.d.ts +1 -0
- package/template-ssr-preact-ts/src/vite-env.d.ts +1 -0
- package/template-ssr-preact-ts/tsconfig.json +23 -0
- package/template-ssr-preact-ts/tsconfig.node.json +16 -0
- package/template-ssr-preact-ts/vite.config.ts +15 -0
- package/template-ssr-react/_gitignore +24 -0
- package/template-ssr-react/index.html +14 -0
- package/template-ssr-react/package.json +27 -0
- package/template-ssr-react/public/vite.svg +1 -0
- package/template-ssr-react/server.js +71 -0
- package/template-ssr-react/src/App.css +41 -0
- package/template-ssr-react/src/App.jsx +34 -0
- package/template-ssr-react/src/assets/react.svg +1 -0
- package/template-ssr-react/src/entry-client.jsx +11 -0
- package/template-ssr-react/src/entry-server.jsx +12 -0
- package/template-ssr-react/src/index.css +70 -0
- package/template-ssr-react/vite.config.js +7 -0
- package/template-ssr-react-ts/_gitignore +24 -0
- package/template-ssr-react-ts/index.html +14 -0
- package/template-ssr-react-ts/package.json +28 -0
- package/template-ssr-react-ts/public/vite.svg +1 -0
- package/template-ssr-react-ts/server.js +71 -0
- package/template-ssr-react-ts/src/App.css +41 -0
- package/template-ssr-react-ts/src/App.tsx +34 -0
- package/template-ssr-react-ts/src/assets/react.svg +1 -0
- package/template-ssr-react-ts/src/entry-client.tsx +11 -0
- package/template-ssr-react-ts/src/entry-server.tsx +12 -0
- package/template-ssr-react-ts/src/index.css +70 -0
- package/template-ssr-react-ts/src/vite-env.d.ts +1 -0
- package/template-ssr-react-ts/tsconfig.json +21 -0
- package/template-ssr-react-ts/tsconfig.node.json +15 -0
- package/template-ssr-react-ts/vite.config.ts +7 -0
- package/template-ssr-svelte/.vscode/extensions.json +3 -0
- package/template-ssr-svelte/README.md +48 -0
- package/template-ssr-svelte/_gitignore +24 -0
- package/template-ssr-svelte/index.html +14 -0
- package/template-ssr-svelte/jsconfig.json +34 -0
- package/template-ssr-svelte/package.json +24 -0
- package/template-ssr-svelte/public/vite.svg +1 -0
- package/template-ssr-svelte/server.js +71 -0
- package/template-ssr-svelte/src/App.svelte +45 -0
- package/template-ssr-svelte/src/app.css +81 -0
- package/template-ssr-svelte/src/assets/svelte.svg +1 -0
- package/template-ssr-svelte/src/entry-client.js +7 -0
- package/template-ssr-svelte/src/entry-server.js +6 -0
- package/template-ssr-svelte/src/lib/Counter.svelte +10 -0
- package/template-ssr-svelte/src/vite-env.d.ts +2 -0
- package/template-ssr-svelte/vite.config.js +13 -0
- package/template-ssr-svelte-ts/.vscode/extensions.json +3 -0
- package/template-ssr-svelte-ts/README.md +48 -0
- package/template-ssr-svelte-ts/_gitignore +24 -0
- package/template-ssr-svelte-ts/index.html +14 -0
- package/template-ssr-svelte-ts/package.json +29 -0
- package/template-ssr-svelte-ts/public/vite.svg +1 -0
- package/template-ssr-svelte-ts/server.js +71 -0
- package/template-ssr-svelte-ts/src/App.svelte +45 -0
- package/template-ssr-svelte-ts/src/app.css +81 -0
- package/template-ssr-svelte-ts/src/assets/svelte.svg +1 -0
- package/template-ssr-svelte-ts/src/entry-client.ts +7 -0
- package/template-ssr-svelte-ts/src/entry-server.ts +6 -0
- package/template-ssr-svelte-ts/src/lib/Counter.svelte +10 -0
- package/template-ssr-svelte-ts/src/vite-env.d.ts +2 -0
- package/template-ssr-svelte-ts/svelte.config.js +7 -0
- package/template-ssr-svelte-ts/tsconfig.json +21 -0
- package/template-ssr-svelte-ts/tsconfig.node.json +8 -0
- package/template-ssr-svelte-ts/vite.config.ts +13 -0
- package/template-ssr-transform/README.md +3 -0
- package/template-ssr-transform/_gitignore +24 -0
- package/template-ssr-transform/package.json +12 -0
- package/template-ssr-transform/src/foo.js +3 -0
- package/template-ssr-transform/src/main.js +5 -0
- package/template-ssr-transform/test.js +13 -0
- package/template-ssr-vanilla/_gitignore +24 -0
- package/template-ssr-vanilla/index.html +14 -0
- package/template-ssr-vanilla/package.json +22 -0
- package/template-ssr-vanilla/public/vite.svg +1 -0
- package/template-ssr-vanilla/server.js +71 -0
- package/template-ssr-vanilla/src/counter.js +9 -0
- package/template-ssr-vanilla/src/entry-client.js +5 -0
- package/template-ssr-vanilla/src/entry-server.js +22 -0
- package/template-ssr-vanilla/src/javascript.svg +1 -0
- package/template-ssr-vanilla/src/style.css +97 -0
- package/template-ssr-vanilla-ts/_gitignore +24 -0
- package/template-ssr-vanilla-ts/index.html +14 -0
- package/template-ssr-vanilla-ts/package.json +25 -0
- package/template-ssr-vanilla-ts/public/vite.svg +1 -0
- package/template-ssr-vanilla-ts/server.js +71 -0
- package/template-ssr-vanilla-ts/src/counter.ts +9 -0
- package/template-ssr-vanilla-ts/src/entry-client.ts +5 -0
- package/template-ssr-vanilla-ts/src/entry-server.ts +22 -0
- package/template-ssr-vanilla-ts/src/style.css +97 -0
- package/template-ssr-vanilla-ts/src/typescript.svg +1 -0
- package/template-ssr-vanilla-ts/src/vite-env.d.ts +1 -0
- package/template-ssr-vanilla-ts/tsconfig.json +22 -0
- package/template-ssr-vanilla-ts/tsconfig.node.json +8 -0
- package/template-ssr-vue/.vscode/extensions.json +3 -0
- package/template-ssr-vue/README.md +7 -0
- package/template-ssr-vue/_gitignore +24 -0
- package/template-ssr-vue/index.html +14 -0
- package/template-ssr-vue/package.json +24 -0
- package/template-ssr-vue/public/vite.svg +1 -0
- package/template-ssr-vue/server.js +71 -0
- package/template-ssr-vue/src/App.vue +31 -0
- package/template-ssr-vue/src/assets/vue.svg +1 -0
- package/template-ssr-vue/src/components/HelloWorld.vue +40 -0
- package/template-ssr-vue/src/entry-client.js +6 -0
- package/template-ssr-vue/src/entry-server.js +15 -0
- package/template-ssr-vue/src/main.js +10 -0
- package/template-ssr-vue/src/style.css +90 -0
- package/template-ssr-vue/vite.config.js +7 -0
- package/template-ssr-vue-ts/.vscode/extensions.json +3 -0
- package/template-ssr-vue-ts/README.md +16 -0
- package/template-ssr-vue-ts/_gitignore +24 -0
- package/template-ssr-vue-ts/index.html +14 -0
- package/template-ssr-vue-ts/package.json +26 -0
- package/template-ssr-vue-ts/public/vite.svg +1 -0
- package/template-ssr-vue-ts/server.js +71 -0
- package/template-ssr-vue-ts/src/App.vue +31 -0
- package/template-ssr-vue-ts/src/assets/vue.svg +1 -0
- package/template-ssr-vue-ts/src/components/HelloWorld.vue +38 -0
- package/template-ssr-vue-ts/src/entry-client.ts +6 -0
- package/template-ssr-vue-ts/src/entry-server.ts +15 -0
- package/template-ssr-vue-ts/src/main.ts +10 -0
- package/template-ssr-vue-ts/src/style.css +81 -0
- package/template-ssr-vue-ts/src/vite-env.d.ts +7 -0
- package/template-ssr-vue-ts/tsconfig.json +18 -0
- package/template-ssr-vue-ts/tsconfig.node.json +9 -0
- package/template-ssr-vue-ts/vite.config.ts +7 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import fs from 'node:fs/promises'
|
|
2
|
+
import express from 'express'
|
|
3
|
+
|
|
4
|
+
// Constants
|
|
5
|
+
const isProduction = process.env.NODE_ENV === 'production'
|
|
6
|
+
const port = process.env.PORT || 5173
|
|
7
|
+
const base = process.env.BASE || '/'
|
|
8
|
+
|
|
9
|
+
// Cached production assets
|
|
10
|
+
const templateHtml = isProduction
|
|
11
|
+
? await fs.readFile('./dist/client/index.html', 'utf-8')
|
|
12
|
+
: ''
|
|
13
|
+
const ssrManifest = isProduction
|
|
14
|
+
? await fs.readFile('./dist/client/ssr-manifest.json', 'utf-8')
|
|
15
|
+
: undefined
|
|
16
|
+
|
|
17
|
+
// Create http server
|
|
18
|
+
const app = express()
|
|
19
|
+
|
|
20
|
+
// Add Vite or respective production middlewares
|
|
21
|
+
let vite
|
|
22
|
+
if (!isProduction) {
|
|
23
|
+
const { createServer } = await import('vite')
|
|
24
|
+
vite = await createServer({
|
|
25
|
+
server: { middlewareMode: true },
|
|
26
|
+
appType: 'custom',
|
|
27
|
+
base
|
|
28
|
+
})
|
|
29
|
+
app.use(vite.middlewares)
|
|
30
|
+
} else {
|
|
31
|
+
const compression = (await import('compression')).default
|
|
32
|
+
const sirv = (await import('sirv')).default
|
|
33
|
+
app.use(compression())
|
|
34
|
+
app.use(base, sirv('./dist/client', { extensions: [] }))
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Serve HTML
|
|
38
|
+
app.use('*', async (req, res) => {
|
|
39
|
+
try {
|
|
40
|
+
const url = req.originalUrl.replace(base, '')
|
|
41
|
+
|
|
42
|
+
let template
|
|
43
|
+
let render
|
|
44
|
+
if (!isProduction) {
|
|
45
|
+
// Always read fresh template in development
|
|
46
|
+
template = await fs.readFile('./index.html', 'utf-8')
|
|
47
|
+
template = await vite.transformIndexHtml(url, template)
|
|
48
|
+
render = (await vite.ssrLoadModule('/src/entry-server.js')).render
|
|
49
|
+
} else {
|
|
50
|
+
template = templateHtml
|
|
51
|
+
render = (await import('./dist/server/entry-server.js')).render
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const rendered = await render(url, ssrManifest)
|
|
55
|
+
|
|
56
|
+
const html = template
|
|
57
|
+
.replace(`<!--app-head-->`, rendered.head ?? '')
|
|
58
|
+
.replace(`<!--app-html-->`, rendered.html ?? '')
|
|
59
|
+
|
|
60
|
+
res.status(200).set({ 'Content-Type': 'text/html' }).end(html)
|
|
61
|
+
} catch (e) {
|
|
62
|
+
vite?.ssrFixStacktrace(e)
|
|
63
|
+
console.log(e.stack)
|
|
64
|
+
res.status(500).end(e.stack)
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
// Start http server
|
|
69
|
+
app.listen(port, () => {
|
|
70
|
+
console.log(`Server started at http://localhost:${port}`)
|
|
71
|
+
})
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import svelteLogo from './assets/svelte.svg'
|
|
3
|
+
import Counter from './lib/Counter.svelte'
|
|
4
|
+
</script>
|
|
5
|
+
|
|
6
|
+
<main>
|
|
7
|
+
<div>
|
|
8
|
+
<a href="https://vitejs.dev" target="_blank">
|
|
9
|
+
<img src="/vite.svg" class="logo" alt="Vite Logo" />
|
|
10
|
+
</a>
|
|
11
|
+
<a href="https://svelte.dev" target="_blank">
|
|
12
|
+
<img src={svelteLogo} class="logo svelte" alt="Svelte Logo" />
|
|
13
|
+
</a>
|
|
14
|
+
</div>
|
|
15
|
+
<h1>Vite + Svelte</h1>
|
|
16
|
+
|
|
17
|
+
<div class="card">
|
|
18
|
+
<Counter />
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
<p>
|
|
22
|
+
Check out <a href="https://github.com/sveltejs/kit#readme" target="_blank">SvelteKit</a>, the official Svelte app framework powered by Vite!
|
|
23
|
+
</p>
|
|
24
|
+
|
|
25
|
+
<p class="read-the-docs">
|
|
26
|
+
Click on the Vite and Svelte logos to learn more
|
|
27
|
+
</p>
|
|
28
|
+
</main>
|
|
29
|
+
|
|
30
|
+
<style>
|
|
31
|
+
.logo {
|
|
32
|
+
height: 6em;
|
|
33
|
+
padding: 1.5em;
|
|
34
|
+
will-change: filter;
|
|
35
|
+
}
|
|
36
|
+
.logo:hover {
|
|
37
|
+
filter: drop-shadow(0 0 2em #646cffaa);
|
|
38
|
+
}
|
|
39
|
+
.logo.svelte:hover {
|
|
40
|
+
filter: drop-shadow(0 0 2em #ff3e00aa);
|
|
41
|
+
}
|
|
42
|
+
.read-the-docs {
|
|
43
|
+
color: #888;
|
|
44
|
+
}
|
|
45
|
+
</style>
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
font-family: Inter, Avenir, Helvetica, Arial, sans-serif;
|
|
3
|
+
font-size: 16px;
|
|
4
|
+
line-height: 24px;
|
|
5
|
+
font-weight: 400;
|
|
6
|
+
|
|
7
|
+
color-scheme: light dark;
|
|
8
|
+
color: rgba(255, 255, 255, 0.87);
|
|
9
|
+
background-color: #242424;
|
|
10
|
+
|
|
11
|
+
font-synthesis: none;
|
|
12
|
+
text-rendering: optimizeLegibility;
|
|
13
|
+
-webkit-font-smoothing: antialiased;
|
|
14
|
+
-moz-osx-font-smoothing: grayscale;
|
|
15
|
+
-webkit-text-size-adjust: 100%;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
a {
|
|
19
|
+
font-weight: 500;
|
|
20
|
+
color: #646cff;
|
|
21
|
+
text-decoration: inherit;
|
|
22
|
+
}
|
|
23
|
+
a:hover {
|
|
24
|
+
color: #535bf2;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
body {
|
|
28
|
+
margin: 0;
|
|
29
|
+
display: flex;
|
|
30
|
+
place-items: center;
|
|
31
|
+
min-width: 320px;
|
|
32
|
+
min-height: 100vh;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
h1 {
|
|
36
|
+
font-size: 3.2em;
|
|
37
|
+
line-height: 1.1;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.card {
|
|
41
|
+
padding: 2em;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
#app {
|
|
45
|
+
max-width: 1280px;
|
|
46
|
+
margin: 0 auto;
|
|
47
|
+
padding: 2rem;
|
|
48
|
+
text-align: center;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
button {
|
|
52
|
+
border-radius: 8px;
|
|
53
|
+
border: 1px solid transparent;
|
|
54
|
+
padding: 0.6em 1.2em;
|
|
55
|
+
font-size: 1em;
|
|
56
|
+
font-weight: 500;
|
|
57
|
+
font-family: inherit;
|
|
58
|
+
background-color: #1a1a1a;
|
|
59
|
+
cursor: pointer;
|
|
60
|
+
transition: border-color 0.25s;
|
|
61
|
+
}
|
|
62
|
+
button:hover {
|
|
63
|
+
border-color: #646cff;
|
|
64
|
+
}
|
|
65
|
+
button:focus,
|
|
66
|
+
button:focus-visible {
|
|
67
|
+
outline: 4px auto -webkit-focus-ring-color;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@media (prefers-color-scheme: light) {
|
|
71
|
+
:root {
|
|
72
|
+
color: #213547;
|
|
73
|
+
background-color: #ffffff;
|
|
74
|
+
}
|
|
75
|
+
a:hover {
|
|
76
|
+
color: #747bff;
|
|
77
|
+
}
|
|
78
|
+
button {
|
|
79
|
+
background-color: #f9f9f9;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="26.6" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 308"><path fill="#FF3E00" d="M239.682 40.707C211.113-.182 154.69-12.301 113.895 13.69L42.247 59.356a82.198 82.198 0 0 0-37.135 55.056a86.566 86.566 0 0 0 8.536 55.576a82.425 82.425 0 0 0-12.296 30.719a87.596 87.596 0 0 0 14.964 66.244c28.574 40.893 84.997 53.007 125.787 27.016l71.648-45.664a82.182 82.182 0 0 0 37.135-55.057a86.601 86.601 0 0 0-8.53-55.577a82.409 82.409 0 0 0 12.29-30.718a87.573 87.573 0 0 0-14.963-66.244"></path><path fill="#FFF" d="M106.889 270.841c-23.102 6.007-47.497-3.036-61.103-22.648a52.685 52.685 0 0 1-9.003-39.85a49.978 49.978 0 0 1 1.713-6.693l1.35-4.115l3.671 2.697a92.447 92.447 0 0 0 28.036 14.007l2.663.808l-.245 2.659a16.067 16.067 0 0 0 2.89 10.656a17.143 17.143 0 0 0 18.397 6.828a15.786 15.786 0 0 0 4.403-1.935l71.67-45.672a14.922 14.922 0 0 0 6.734-9.977a15.923 15.923 0 0 0-2.713-12.011a17.156 17.156 0 0 0-18.404-6.832a15.78 15.78 0 0 0-4.396 1.933l-27.35 17.434a52.298 52.298 0 0 1-14.553 6.391c-23.101 6.007-47.497-3.036-61.101-22.649a52.681 52.681 0 0 1-9.004-39.849a49.428 49.428 0 0 1 22.34-33.114l71.664-45.677a52.218 52.218 0 0 1 14.563-6.398c23.101-6.007 47.497 3.036 61.101 22.648a52.685 52.685 0 0 1 9.004 39.85a50.559 50.559 0 0 1-1.713 6.692l-1.35 4.116l-3.67-2.693a92.373 92.373 0 0 0-28.037-14.013l-2.664-.809l.246-2.658a16.099 16.099 0 0 0-2.89-10.656a17.143 17.143 0 0 0-18.398-6.828a15.786 15.786 0 0 0-4.402 1.935l-71.67 45.674a14.898 14.898 0 0 0-6.73 9.975a15.9 15.9 0 0 0 2.709 12.012a17.156 17.156 0 0 0 18.404 6.832a15.841 15.841 0 0 0 4.402-1.935l27.345-17.427a52.147 52.147 0 0 1 14.552-6.397c23.101-6.006 47.497 3.037 61.102 22.65a52.681 52.681 0 0 1 9.003 39.848a49.453 49.453 0 0 1-22.34 33.12l-71.664 45.673a52.218 52.218 0 0 1-14.563 6.398"></path></svg>
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Svelte + TS + Vite
|
|
2
|
+
|
|
3
|
+
This template should help get you started developing with Svelte and TypeScript in Vite.
|
|
4
|
+
|
|
5
|
+
## Recommended IDE Setup
|
|
6
|
+
|
|
7
|
+
[VS Code](https://code.visualstudio.com/) + [Svelte](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode).
|
|
8
|
+
|
|
9
|
+
## Need an official Svelte framework?
|
|
10
|
+
|
|
11
|
+
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.
|
|
12
|
+
|
|
13
|
+
## Technical considerations
|
|
14
|
+
|
|
15
|
+
**Why use this over SvelteKit?**
|
|
16
|
+
|
|
17
|
+
- It brings its own routing solution which might not be preferable for some users.
|
|
18
|
+
- It is first and foremost a framework that just happens to use Vite under the hood, not a Vite app.
|
|
19
|
+
`vite dev` and `vite build` wouldn't work in a SvelteKit environment, for example.
|
|
20
|
+
|
|
21
|
+
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.
|
|
22
|
+
|
|
23
|
+
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.
|
|
24
|
+
|
|
25
|
+
**Why `global.d.ts` instead of `compilerOptions.types` inside `jsconfig.json` or `tsconfig.json`?**
|
|
26
|
+
|
|
27
|
+
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.
|
|
28
|
+
|
|
29
|
+
**Why include `.vscode/extensions.json`?**
|
|
30
|
+
|
|
31
|
+
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.
|
|
32
|
+
|
|
33
|
+
**Why enable `allowJs` in the TS template?**
|
|
34
|
+
|
|
35
|
+
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.
|
|
36
|
+
|
|
37
|
+
**Why is HMR not preserving my local component state?**
|
|
38
|
+
|
|
39
|
+
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).
|
|
40
|
+
|
|
41
|
+
If you have state that's important to retain within a component, consider creating an external store which would not be replaced by HMR.
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
// store.ts
|
|
45
|
+
// An extremely simple external store
|
|
46
|
+
import { writable } from 'svelte/store'
|
|
47
|
+
export default writable(0)
|
|
48
|
+
```
|
|
@@ -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?
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
<!--app-head-->
|
|
9
|
+
</head>
|
|
10
|
+
<body>
|
|
11
|
+
<div id="app"><!--app-html--></div>
|
|
12
|
+
<script type="module" src="/src/entry-client.ts"></script>
|
|
13
|
+
</body>
|
|
14
|
+
</html>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vite-svelte-ts-starter",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "node server",
|
|
8
|
+
"build": "npm run build:client && npm run build:server",
|
|
9
|
+
"build:client": "vite build --ssrManifest --outDir dist/client",
|
|
10
|
+
"build:server": "vite build --ssr src/entry-server.ts --outDir dist/server",
|
|
11
|
+
"preview": "cross-env NODE_ENV=production node server"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"compression": "^1.7.4",
|
|
15
|
+
"express": "^4.18.1",
|
|
16
|
+
"sirv": "^2.0.2"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@sveltejs/vite-plugin-svelte": "^1.0.1",
|
|
20
|
+
"@tsconfig/svelte": "^3.0.0",
|
|
21
|
+
"cross-env": "^7.0.3",
|
|
22
|
+
"svelte": "^3.49.0",
|
|
23
|
+
"svelte-check": "^2.8.0",
|
|
24
|
+
"svelte-preprocess": "^4.10.7",
|
|
25
|
+
"tslib": "^2.4.0",
|
|
26
|
+
"typescript": "^4.6.4",
|
|
27
|
+
"vite": "^3.0.1"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import fs from 'node:fs/promises'
|
|
2
|
+
import express from 'express'
|
|
3
|
+
|
|
4
|
+
// Constants
|
|
5
|
+
const isProduction = process.env.NODE_ENV === 'production'
|
|
6
|
+
const port = process.env.PORT || 5173
|
|
7
|
+
const base = process.env.BASE || '/'
|
|
8
|
+
|
|
9
|
+
// Cached production assets
|
|
10
|
+
const templateHtml = isProduction
|
|
11
|
+
? await fs.readFile('./dist/client/index.html', 'utf-8')
|
|
12
|
+
: ''
|
|
13
|
+
const ssrManifest = isProduction
|
|
14
|
+
? await fs.readFile('./dist/client/ssr-manifest.json', 'utf-8')
|
|
15
|
+
: undefined
|
|
16
|
+
|
|
17
|
+
// Create http server
|
|
18
|
+
const app = express()
|
|
19
|
+
|
|
20
|
+
// Add Vite or respective production middlewares
|
|
21
|
+
let vite
|
|
22
|
+
if (!isProduction) {
|
|
23
|
+
const { createServer } = await import('vite')
|
|
24
|
+
vite = await createServer({
|
|
25
|
+
server: { middlewareMode: true },
|
|
26
|
+
appType: 'custom',
|
|
27
|
+
base
|
|
28
|
+
})
|
|
29
|
+
app.use(vite.middlewares)
|
|
30
|
+
} else {
|
|
31
|
+
const compression = (await import('compression')).default
|
|
32
|
+
const sirv = (await import('sirv')).default
|
|
33
|
+
app.use(compression())
|
|
34
|
+
app.use(base, sirv('./dist/client', { extensions: [] }))
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Serve HTML
|
|
38
|
+
app.use('*', async (req, res) => {
|
|
39
|
+
try {
|
|
40
|
+
const url = req.originalUrl.replace(base, '')
|
|
41
|
+
|
|
42
|
+
let template
|
|
43
|
+
let render
|
|
44
|
+
if (!isProduction) {
|
|
45
|
+
// Always read fresh template in development
|
|
46
|
+
template = await fs.readFile('./index.html', 'utf-8')
|
|
47
|
+
template = await vite.transformIndexHtml(url, template)
|
|
48
|
+
render = (await vite.ssrLoadModule('/src/entry-server.ts')).render
|
|
49
|
+
} else {
|
|
50
|
+
template = templateHtml
|
|
51
|
+
render = (await import('./dist/server/entry-server.js')).render
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const rendered = await render(url, ssrManifest)
|
|
55
|
+
|
|
56
|
+
const html = template
|
|
57
|
+
.replace(`<!--app-head-->`, rendered.head ?? '')
|
|
58
|
+
.replace(`<!--app-html-->`, rendered.html ?? '')
|
|
59
|
+
|
|
60
|
+
res.status(200).set({ 'Content-Type': 'text/html' }).end(html)
|
|
61
|
+
} catch (e) {
|
|
62
|
+
vite?.ssrFixStacktrace(e)
|
|
63
|
+
console.log(e.stack)
|
|
64
|
+
res.status(500).end(e.stack)
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
// Start http server
|
|
69
|
+
app.listen(port, () => {
|
|
70
|
+
console.log(`Server started at http://localhost:${port}`)
|
|
71
|
+
})
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import svelteLogo from './assets/svelte.svg'
|
|
3
|
+
import Counter from './lib/Counter.svelte'
|
|
4
|
+
</script>
|
|
5
|
+
|
|
6
|
+
<main>
|
|
7
|
+
<div>
|
|
8
|
+
<a href="https://vitejs.dev" target="_blank">
|
|
9
|
+
<img src="/vite.svg" class="logo" alt="Vite Logo" />
|
|
10
|
+
</a>
|
|
11
|
+
<a href="https://svelte.dev" target="_blank">
|
|
12
|
+
<img src={svelteLogo} class="logo svelte" alt="Svelte Logo" />
|
|
13
|
+
</a>
|
|
14
|
+
</div>
|
|
15
|
+
<h1>Vite + Svelte</h1>
|
|
16
|
+
|
|
17
|
+
<div class="card">
|
|
18
|
+
<Counter />
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
<p>
|
|
22
|
+
Check out <a href="https://github.com/sveltejs/kit#readme" target="_blank">SvelteKit</a>, the official Svelte app framework powered by Vite!
|
|
23
|
+
</p>
|
|
24
|
+
|
|
25
|
+
<p class="read-the-docs">
|
|
26
|
+
Click on the Vite and Svelte logos to learn more
|
|
27
|
+
</p>
|
|
28
|
+
</main>
|
|
29
|
+
|
|
30
|
+
<style>
|
|
31
|
+
.logo {
|
|
32
|
+
height: 6em;
|
|
33
|
+
padding: 1.5em;
|
|
34
|
+
will-change: filter;
|
|
35
|
+
}
|
|
36
|
+
.logo:hover {
|
|
37
|
+
filter: drop-shadow(0 0 2em #646cffaa);
|
|
38
|
+
}
|
|
39
|
+
.logo.svelte:hover {
|
|
40
|
+
filter: drop-shadow(0 0 2em #ff3e00aa);
|
|
41
|
+
}
|
|
42
|
+
.read-the-docs {
|
|
43
|
+
color: #888;
|
|
44
|
+
}
|
|
45
|
+
</style>
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
font-family: Inter, Avenir, Helvetica, Arial, sans-serif;
|
|
3
|
+
font-size: 16px;
|
|
4
|
+
line-height: 24px;
|
|
5
|
+
font-weight: 400;
|
|
6
|
+
|
|
7
|
+
color-scheme: light dark;
|
|
8
|
+
color: rgba(255, 255, 255, 0.87);
|
|
9
|
+
background-color: #242424;
|
|
10
|
+
|
|
11
|
+
font-synthesis: none;
|
|
12
|
+
text-rendering: optimizeLegibility;
|
|
13
|
+
-webkit-font-smoothing: antialiased;
|
|
14
|
+
-moz-osx-font-smoothing: grayscale;
|
|
15
|
+
-webkit-text-size-adjust: 100%;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
a {
|
|
19
|
+
font-weight: 500;
|
|
20
|
+
color: #646cff;
|
|
21
|
+
text-decoration: inherit;
|
|
22
|
+
}
|
|
23
|
+
a:hover {
|
|
24
|
+
color: #535bf2;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
body {
|
|
28
|
+
margin: 0;
|
|
29
|
+
display: flex;
|
|
30
|
+
place-items: center;
|
|
31
|
+
min-width: 320px;
|
|
32
|
+
min-height: 100vh;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
h1 {
|
|
36
|
+
font-size: 3.2em;
|
|
37
|
+
line-height: 1.1;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.card {
|
|
41
|
+
padding: 2em;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
#app {
|
|
45
|
+
max-width: 1280px;
|
|
46
|
+
margin: 0 auto;
|
|
47
|
+
padding: 2rem;
|
|
48
|
+
text-align: center;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
button {
|
|
52
|
+
border-radius: 8px;
|
|
53
|
+
border: 1px solid transparent;
|
|
54
|
+
padding: 0.6em 1.2em;
|
|
55
|
+
font-size: 1em;
|
|
56
|
+
font-weight: 500;
|
|
57
|
+
font-family: inherit;
|
|
58
|
+
background-color: #1a1a1a;
|
|
59
|
+
cursor: pointer;
|
|
60
|
+
transition: border-color 0.25s;
|
|
61
|
+
}
|
|
62
|
+
button:hover {
|
|
63
|
+
border-color: #646cff;
|
|
64
|
+
}
|
|
65
|
+
button:focus,
|
|
66
|
+
button:focus-visible {
|
|
67
|
+
outline: 4px auto -webkit-focus-ring-color;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@media (prefers-color-scheme: light) {
|
|
71
|
+
:root {
|
|
72
|
+
color: #213547;
|
|
73
|
+
background-color: #ffffff;
|
|
74
|
+
}
|
|
75
|
+
a:hover {
|
|
76
|
+
color: #747bff;
|
|
77
|
+
}
|
|
78
|
+
button {
|
|
79
|
+
background-color: #f9f9f9;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="26.6" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 308"><path fill="#FF3E00" d="M239.682 40.707C211.113-.182 154.69-12.301 113.895 13.69L42.247 59.356a82.198 82.198 0 0 0-37.135 55.056a86.566 86.566 0 0 0 8.536 55.576a82.425 82.425 0 0 0-12.296 30.719a87.596 87.596 0 0 0 14.964 66.244c28.574 40.893 84.997 53.007 125.787 27.016l71.648-45.664a82.182 82.182 0 0 0 37.135-55.057a86.601 86.601 0 0 0-8.53-55.577a82.409 82.409 0 0 0 12.29-30.718a87.573 87.573 0 0 0-14.963-66.244"></path><path fill="#FFF" d="M106.889 270.841c-23.102 6.007-47.497-3.036-61.103-22.648a52.685 52.685 0 0 1-9.003-39.85a49.978 49.978 0 0 1 1.713-6.693l1.35-4.115l3.671 2.697a92.447 92.447 0 0 0 28.036 14.007l2.663.808l-.245 2.659a16.067 16.067 0 0 0 2.89 10.656a17.143 17.143 0 0 0 18.397 6.828a15.786 15.786 0 0 0 4.403-1.935l71.67-45.672a14.922 14.922 0 0 0 6.734-9.977a15.923 15.923 0 0 0-2.713-12.011a17.156 17.156 0 0 0-18.404-6.832a15.78 15.78 0 0 0-4.396 1.933l-27.35 17.434a52.298 52.298 0 0 1-14.553 6.391c-23.101 6.007-47.497-3.036-61.101-22.649a52.681 52.681 0 0 1-9.004-39.849a49.428 49.428 0 0 1 22.34-33.114l71.664-45.677a52.218 52.218 0 0 1 14.563-6.398c23.101-6.007 47.497 3.036 61.101 22.648a52.685 52.685 0 0 1 9.004 39.85a50.559 50.559 0 0 1-1.713 6.692l-1.35 4.116l-3.67-2.693a92.373 92.373 0 0 0-28.037-14.013l-2.664-.809l.246-2.658a16.099 16.099 0 0 0-2.89-10.656a17.143 17.143 0 0 0-18.398-6.828a15.786 15.786 0 0 0-4.402 1.935l-71.67 45.674a14.898 14.898 0 0 0-6.73 9.975a15.9 15.9 0 0 0 2.709 12.012a17.156 17.156 0 0 0 18.404 6.832a15.841 15.841 0 0 0 4.402-1.935l27.345-17.427a52.147 52.147 0 0 1 14.552-6.397c23.101-6.006 47.497 3.037 61.102 22.65a52.681 52.681 0 0 1 9.003 39.848a49.453 49.453 0 0 1-22.34 33.12l-71.664 45.673a52.218 52.218 0 0 1-14.563 6.398"></path></svg>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "@tsconfig/svelte/tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"target": "ESNext",
|
|
5
|
+
"useDefineForClassFields": true,
|
|
6
|
+
"module": "ESNext",
|
|
7
|
+
"resolveJsonModule": true,
|
|
8
|
+
"baseUrl": ".",
|
|
9
|
+
/**
|
|
10
|
+
* Typecheck JS in `.svelte` and `.js` files by default.
|
|
11
|
+
* Disable checkJs if you'd like to use dynamic types in JS.
|
|
12
|
+
* Note that setting allowJs false does not prevent the use
|
|
13
|
+
* of JS in `.svelte` files.
|
|
14
|
+
*/
|
|
15
|
+
"allowJs": true,
|
|
16
|
+
"checkJs": true,
|
|
17
|
+
"isolatedModules": true
|
|
18
|
+
},
|
|
19
|
+
"include": ["src/**/*.d.ts", "src/**/*.ts", "src/**/*.js", "src/**/*.svelte"],
|
|
20
|
+
"references": [{ "path": "./tsconfig.node.json" }]
|
|
21
|
+
}
|