Thevetats Ramblings

Explore

About
Blogs
Misc
Resume
Services
Testing
Tools

Blogs

Env

Freshstart

Aliases
How I config my System76
Un-F%ck your M2 for development
ZSH Functions

Toolbelt

What's usually in the workvan

Rust

Notes

Primeagen's Rust for TS Devs

RustGoTs

Primeagen's Polyglot Class 1
Primeagen's Polyglot Class 2
Primeagen's Polyglot Class 3

Tauri

Setting up Tauri with Vite

WebDev

Ai

TheBeast

Slaying the beast

ComponentLibary

Salt Life
Submodules in Git

Sql

Useful SQL

Unocss

Just one more...
Setting up UnoCSS in a Vite Project

Vue

Reference

Suspense
Transitions

Setting up Tauri with Vite

Published
February 26, 2023
Tags
#vite#typescript#rust

Table of Contents

  • Linux Preqreq

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.

Project Docs

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.

bash
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

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

bash
pnpm add -D @tauri-apps/cli

Linux Preqreq

bash
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

bash
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...

bash
rustup update
Made from scratch with ❤️ by Thevetat