Template for building SvelteKit + Tauri (Skitty)
This project is supposed to be used temporary only (until svelte-add
tauri is released).
Consider checking svlete-add
before continue.
$ git clone https://github.com/Mattchine/skitty <your path>
$ cd <your path>
$ yarn install
$ yarn tauri dev
- Create project with svelte-add
$ npm init @svelte-add/kit@latest
# Follow the prompts to select the integrations you want
- Add Tauri to your project
$ cd <your path>
$ yarn add -D @tauri-apps/cli
$ yarn add @tauri-apps/api
- Disable SvelteKit SSR (I have problem with this for days, thanks to jsmenzies)
- 3.1 Create
src/hooks/index.ts
/** @type {import('@sveltejs/kit').Handle} */
export async function handle({ event, resolve }) {
return await resolve(event, {
ssr: false
});
}
- 3.2 Add
hooks/index.ts
tosvelte.config.js
kit: {
files: {
hooks: 'src/hooks/index.ts'
}
}
- Change tauri config
src-tauri/tauri.conf.json
- 4.1 Change
devPath
from PORT8080
to3000
- 4.2 Set
beforeDevCommand
andbeforeBuildCommand
"build": {
"distDir": "../public",
"devPath": "http://localhost:3000",
"beforeDevCommand": "yarn dev",
"beforeBuildCommand": "yarn build"
},
- Now you can run
$ yarn tauri dev
- But if you try
yarn tauri build
, it won't work right now. We need to fixdistDir
. Again, changesrc-tauri/tauri.conf.json
"build": {
"distDir": "../build",
}
- But where is
build
? Well, you have to tell svelte that you need static-site with adapter static.
- 7.1 Install
adapter-static
first
$ yarn add -D @sveltejs/adapter-static@next
- 7.2 Change
svelte.config.js
as follows.
import staticAdapter from '@sveltejs/adapter-static';
// ...
kit: {
adapter: staticAdapter(),
prerender: {
default: true,
},
files: {
hooks: 'src/hooks/index.ts'
}
}
- Now both
yarn tauri dev
andyarn tauri build
will works just fine. - (Optional) Adding path alias, following the instruction in sveltekit FAQ.
- As you can see in the template you can use
import '$styles/app.css'
or any other path alias
- This repository is for my future self and hope it would help someone out there too.
- jsmenzies
- svelte-add
- And, of course, all underlying project:
Svelte
,SvelteKit
,Taiilwind
,Tauri
, and many mores!.