This python script automates the creation of a SvelteKit + Tauri project using the default SvelteKit and Tauri command line tools, ensuring you are always setting up with the most up-to-date packages and official generated files.
-
Creates a SvelteKit project using
sv create
-
Adds packages available within the interactive version of
sv create
usingsv add
- Customization details here: SvelteKit docs)
- Note: adapter-static is required
-
Adds the Tauri CLI and Tauri JS API packages (for using Tauri invoke, etc.)
-
Installs dependencies with
npm
-
Creates a Tauri project and customizes it for use with SvelteKit using
tauri init
-
Adds a layout.ts file in the root route with
prerendering = true
andssr = false
- Uses
npm
- Installs specific SvelteKit add-ons from the official CLI tool (see below for list)
Note
If you haven't already, install:
- Node JS
- Rust
- Tauri dependencies (will vary depending on if you're developing on windows, linux, or macOS)
-
Set the
default_project_root
variable in the script to the location you want to install the project (this folder will be the root) -
Run:
python ./setup-sv-tauri.py
python ./setup-sv-tauri.py "path/to/folder"
Note: The --clean
flag will delete and remake the provided project dir
- Edit the unique identifier in tauri.conf.json to match your project
- (Optionally) Edit the window and app name from the default, which is your folder name
# Run from root folder
npx tauri dev
OR
# Run from /src-tauri/ folder
cargo tauri dev
# Build from root folder
npx tauri build
OR
# Build from /src-tauri/ folder
cargo tauri build
Done!
- Typescript
- Minimal project scaffolding
- Prettier
- ESlint
- TailwindCSS (+typography/forms)
- Vitest
- Adapter-Static (required for Tauri)
- mdsvex
If you haven't used SvelteKit with Tauri before, you should know that this method requires Sveltekit projects to be rendered statically, which disables use of any server-side (SSR) functionality. You will essentially be using Tauri and Rust as your backend for things like authentication and database management. The plus side is that Rust is an extremely performant language and can do anything you could do with SSR, just with a little less convenience. Of course, it also gives you local file access, which is a huge benefit if it fits your use case.
Generally speaking:
- Use load functions to get data in layout.ts and page.ts files
- Use client-side form validation with tauri invoke to submit forms and perform CRUD operations
- Use Tauri stores for persistent data like user settings
📦SvelteTauri-App
┣ 📂src
┃ ┣ 📂lib
┃ ┣ 📂routes
┃ ┃ ┣ 📜+layout.svelte
┃ ┃ ┣ 📜+layout.ts
┃ ┃ ┗ 📜+page.svelte
┃ ┣ 📜app.css
┃ ┣ 📜app.d.ts
┃ ┣ 📜app.html
┃ ┗ 📜demo.spec.ts
┣ 📂src-tauri
┃ ┣ 📂capabilities
┃ ┣ 📂icons
┃ ┣ 📂src
┃ ┃ ┣ 📜lib.rs
┃ ┃ ┗ 📜main.rs
┃ ┣ 📜.gitignore
┃ ┣ 📜build.rs
┃ ┣ 📜Cargo.toml
┃ ┗ 📜tauri.conf.json
┣ 📂static
┣ 📜.gitignore
┣ 📜.npmrc
┣ 📜.prettierignore
┣ 📜.prettierrc
┣ 📜eslint.config.js
┣ 📜package-lock.json
┣ 📜package.json
┣ 📜README.md
┣ 📜svelte.config.js
┣ 📜tsconfig.json
┗ 📜vite.config.ts
Feel free to fork and customize or contribute by adding a script for another language!