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
using sv add
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
and ssr = false
npm
[!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
# 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!
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:
📦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!