diff --git a/Cargo.lock b/Cargo.lock index c0ba0b2..2012a82 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "addr2line" @@ -5074,23 +5074,24 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.92" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" +checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5" dependencies = [ "cfg-if", + "once_cell", + "rustversion", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.92" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" +checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6" dependencies = [ "bumpalo", "log", - "once_cell", "proc-macro2", "quote", "syn 2.0.60", @@ -5111,9 +5112,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.92" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" +checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -5121,9 +5122,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.92" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" +checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" dependencies = [ "proc-macro2", "quote", @@ -5134,9 +5135,12 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.92" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" +checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d" +dependencies = [ + "unicode-ident", +] [[package]] name = "wasm-streams" diff --git a/Cargo.toml b/Cargo.toml index 6e35eaf..693bbcf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,6 @@ opt-level = 1 opt-level = 3 [[workspace.metadata.leptos]] -# project name name = "{{project-name}}" bin-package = "server" lib-package = "frontend" diff --git a/README.md b/README.md index 3c49fd0..e743c64 100644 --- a/README.md +++ b/README.md @@ -1,37 +1,95 @@ # Tailwind-Leptos-Tauri Template -Simple template to use ssr leptos with tauri for ios/android/windows/macos/linux and web dev +Simple template to use SSR leptos with Tauri for iOS, Android, Windows, Mac, Linux and Web. -To get started just use cargo generate with this repo. +To get started just use [cargo generate](https://crates.io/crates/cargo-generate) with this repo. ```bash cargo generate --git https://github.com/Alt-iOS/tailwind-leptos-tauri-template.git ``` -To test everything is working, run `cargo tauri dev` and `cargo leptos watch` to see the app in the browser and app. - -Thanks to the leptos and tauri teams for the amazing work. +Thanks to the Leptos and Tauri teams for the amazing work. Also all credit to [sjud](https://github.com/sjud/leptos_tauri_from_scratch/tree/main) and [Krzysztof](https://gitlab.com/cristofa/tauri-leptos-template) for their examples, as they were the base for this template. This project differs as it: -- Adds tailwind to sjud's example +- Adds Tailwind to sjud's example - Adds SSR to Krzysztof - Separates the server from the frontend crate - Separated the app module from the frontend crate - Separated the backend logic from the rest -Structure: +## Structure +- `/app/` - UI section +- `/frontend/` - launch point for the hydration/csr +- `/backend/` - server logic and server functions +- `/server/` - the launch point of the axum server +- `/src-tauri/` - Tauri related settings, build script + +## Test everything is working + +### Prerequisites +#### 1. Tauri CLI +> See if Tauri CLI is installed: +> ``` +> cargo tauri --version +> ``` +Install Tauri CLI: +```bash +cargo install tauri-cli +``` + +#### 2. Leptos CLI +> See if Leptos CLI is installed: +> ``` +> cargo leptos --version +> ``` +Install Leptos CLI: +`cargo-leptos` has a dependency on `openssl-sys` that requires Perl to compile. +1. Download portable Strawberry Perl from https://strawberryperl.com/ +1. Extract it +1. Run `portableshell.bat` +1. From that shell go to this project directory +1. Install Leptos CLI using +```bash +cargo install cargo-leptos +``` + +#### 3. wasm32-unknown-unknown target +> See if the target is installed: +> ```bash +> rustup target list --installed +> ``` +Install the target: +```bash +rustup target add wasm32-unknown-unknown +``` -- App: UI section -- frontend: launch point for the hydration/csr -- backend: server logic and server functions -- server: the launch point of the axum server -- src-tauri: tauri related settings, build script +### Launch native app +```bash +cargo tauri dev +``` + +### Serve web app +```bash +cargo leptos watch +``` + +## How To +### Update wasm-bindgen version +``` +cargo update -p wasm-bindgen --precise +``` +Recompile frontend: +``` +cd frontend +cargo clean +cargo leptos build +``` -Mobile dev: +## Mobile dev `cargo tauri android init && cargo tauri ios init` - iOS requires a mac and XCode - Android requires JVM 17 or modifying the gradle version. - You can changge it in the distributionUrl and for compatibility [check](https://docs.gradle.org/current/userguide/compatibility.html) + You can change it in the distributionUrl and for compatibility [check](https://docs.gradle.org/current/userguide/compatibility.html) diff --git a/cargo-generate.toml b/cargo-generate.toml new file mode 100644 index 0000000..0cffedc --- /dev/null +++ b/cargo-generate.toml @@ -0,0 +1,21 @@ +[template] +# This is the correct syntax for older versions that don't support wildcards. +# We list every single problematic file by its full path from the project root. +exclude = [ + "src-tauri/icons/128x128.png", + "src-tauri/icons/128x128@2x.png", + "src-tauri/icons/32x32.png", + "src-tauri/icons/Square107x107Logo.png", + "src-tauri/icons/Square142x142Logo.png", + "src-tauri/icons/Square150x150Logo.png", + "src-tauri/icons/Square284x284Logo.png", + "src-tauri/icons/Square30x30Logo.png", + "src-tauri/icons/Square310x310Logo.png", + "src-tauri/icons/Square44x44Logo.png", + "src-tauri/icons/Square71x71Logo.png", + "src-tauri/icons/Square89x89Logo.png", + "src-tauri/icons/StoreLogo.png", + "src-tauri/icons/icon.icns", + "src-tauri/icons/icon.ico", + "src-tauri/icons/icon.png" +] diff --git a/src-tauri/.cargo/config.toml b/src-tauri/.cargo/config.toml deleted file mode 100644 index 886913a..0000000 --- a/src-tauri/.cargo/config.toml +++ /dev/null @@ -1,4 +0,0 @@ -[build] -target = "aarch64-apple-darwin" - -[target] diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 7749175..413cb5d 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -17,5 +17,6 @@ serde_json = "*" #tauri-plugin-devtools = { git = "https://github.com/crabnebula-dev/devtools", version = "2.0.0-beta.0" } [features] +mobile = [] #default = ["custom-protocol"] custom-protocol = ["tauri/custom-protocol"] diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index a8e1845..b822a7e 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -1,4 +1,4 @@ -#[cfg_attr(mobile, tauri::mobile_entry_point)] +#[cfg_attr(feature = "mobile", tauri::mobile_entry_point)] pub fn run() { tauri::Builder::default() .run(tauri::generate_context!()) diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 4ea44f3..e18c8f0 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -1,5 +1,5 @@ { - "productName": "{{project-name}}_app", + "productName": "{{project-name}}-app", "version": "0.1.0", "identifier": "com.tauri.dev0", "build": { @@ -16,7 +16,7 @@ { "fullscreen": false, "resizable": true, - "title": "template", + "title": "{{project-name}}", "width": 800, "height": 600 } diff --git a/tailwind.config.js b/tailwind.config.js deleted file mode 100644 index 6e830a8..0000000 --- a/tailwind.config.js +++ /dev/null @@ -1,11 +0,0 @@ -/** @type {import('tailwindcss').Config} */ -module.exports = { - content: { - relative: true, - files: ["./*.html", "./app/src/**/*.rs"], - }, - theme: { - extend: {}, - }, - plugins: [], -}; diff --git a/tailwind.config.yaml b/tailwind.config.yaml new file mode 100644 index 0000000..3a46cc7 --- /dev/null +++ b/tailwind.config.yaml @@ -0,0 +1,8 @@ +content: + relative: true + files: + - "./*.html" + - "./app/src/**/*.rs" +theme: + extend: {} +plugins: []