Setting up Tauri with Vite
- Published
- Tags
- #vite#typescript#rust
Tauri Vite Template
Seems I spend more time writing templates snippets and tools for development than for anything else. But hey, boilerplate sucks.
With that said, lets get into making a Tauri template. Really need to get back into rust, and merging typescript and rust together should be the best solution. By doing this I will be able to do any of the lifting I need to in node, but I can try and default to rust as a learning experience.
Starting off. Lets open up the docs and clone some project repos.
You can follow along but this post will summize the relevant details.
Links For Repos: TODO: Unpublished
Run the ol gcvb and clone our vite template.
gcvb() {
cd ~/Git/Vite
git clone git@gitlab.com:thevetat/vite-base.git "$*"
cd "$*"
rm -r -f .git
git init
pnpm i
}
Per the docs lets hop into vite.config.ts
import { defineConfig } from 'vite'
export default defineConfig({
// prevent vite from obscuring rust errors
clearScreen: false,
// Tauri expects a fixed port, fail if that port is not available
server: {
strictPort: true,
},
// to make use of `TAURI_PLATFORM`, `TAURI_ARCH`, `TAURI_FAMILY`,
// `TAURI_PLATFORM_VERSION`, `TAURI_PLATFORM_TYPE` and `TAURI_DEBUG`
// env variables
envPrefix: ['VITE_', 'TAURI_'],
build: {
// Tauri uses Chromium on Windows and WebKit on macOS and Linux
target: process.env.TAURI_PLATFORM == 'windows' ? 'chrome105' : 'safari13',
// don't minify for debug builds
minify: !process.env.TAURI_DEBUG ? 'esbuild' : false,
// produce sourcemaps for debug builds
sourcemap: !!process.env.TAURI_DEBUG,
},
})
Now this is what they say we need to add in. See what changes we gotta make for our template.
Well. Nothing. Just slapped that bad boy on the top of the config, lets see if it works. I do have questions if the SSG will be an issue, totally not needed, but I do not want to rip it out right now. Was not an issue with the elecron template.
Next we
pnpm add -D @tauri-apps/cli
Linux Preqreq
sudo apt update
sudo apt install libwebkit2gtk-4.0-dev \
build-essential \
curl \
wget \
libssl-dev \
libgtk-3-dev \
libayatana-appindicator3-dev \
librsvg2-dev
Install Rust if you havent
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh
Or, if you are an idiot like me and get an error, update rust. Which makes me wonder if this fixed it or what, since I thought backwards compatible and all that...
rustup update