npm create svelteway@latest my-app
cd my-app
npm install
npm run dev
Setup SvelteWay on your existing SvelteKit application.
npm install -D svelteway
Make sure you have configured Tailwind CSS and Daisy UI on your project.
// ...
import type { LayoutServerLoad } from './$types'
import { cwd } from 'process'
import fs from 'node:fs'
export const load = (async ({ route })
=> {
// ...
const currentDirectory = cwd()
const fileToRead = route.id == '/'
? `${currentDirectory}/src/routes/+page.svelte`
: `${currentDirectory}/src/routes/${route.id}/+page.svelte`
const themeFile = `${currentDirectory}/static/theme.txt`
const themeContent = await fs.promises.readFile(themeFile)
const content = await fs.promises.readFile(fileToRead)
return {
data: {
// ...
source: content.toString('utf8'),
file: fileToRead,
theme: JSON.stringify(themeContent.toString('utf8'))
}
};
}) satisfies LayoutServerLoad;
<script>
// ...
import '../app.css'
import { Layout } from 'svelteway'
export let data;
const theme = JSON.parse(data.data.theme)
</script>
<Layout {data}>
// ...
<div data-theme={theme}>
<slot />
</div>
</Layout>
// Update scripts
"dev": "svelteway dev && vite dev",
"build": "svelteway build && vite build"
// ...