maiertech / template-tauri-sveltekit

A GitHub template for a Tauri v2 app with SvelteKit and JSDoc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

template-tauri-sveltekit

This is a Tauri v2 GitHub template, which uses SvelteKit as its frontend.

Updating dependencies

Tauri

Run

pnpm create tauri-app .

from the project root to update dependencies.

SvelteKit

The SvelteKit app bootstrapped by Tauri does not come with ESLint and Prettier. I added them manually. You can update the SvelteKit part separately by running

pnpm create sveltekit@latest .

Follow the instructions in template-sveltekit-example. But you need to review changed files because this command overrides some of the files generated by Tauri.

adapter-static

Tauri generates a SvelteKit app with adapter-static. In combination with Tauri, you cannot use SvelteKit's server-side features. In a Tauri app, anything that SvelteKit would handle server-side, should be handled by Tauri's Rust backend.

The adapter-static generates the index.html file that Tauri launches inside the webview.

Normally, you use adapter-static with these two settings in /src/routes/+layout.ts:

  • prerender = true: Generate an HTML page for each route. You can enter the application through each generated page and fromt there the app will be hydrated.
  • ssr = true: Server-side render all pages at build time. This means that the HTML pages are rendered at build time. Otherwise they would be empty and rendered client-side.

In combination with Tauri, you should set ssr = false because Tauri requires acccess to window, which is not availalbe during SSR. You can set ssr = true but then you would have to use client-side checks before using Tauri's API. And you have to make sure that all dependecies are also server-side renderable.

You can also create a true SPA app by setting prerender = false in combination with ssr = false. But then you need to configure a fallback page index.html in for the static-adapter.

References

About

A GitHub template for a Tauri v2 app with SvelteKit and JSDoc


Languages

Language:Svelte 46.5%Language:JavaScript 31.1%Language:Rust 12.0%Language:HTML 5.8%Language:TypeScript 4.6%