### Install vite-plugin-tauri Source: https://github.com/amrbashir/vite-plugin-tauri/blob/master/README.md Install the plugin and Tauri CLI using your preferred package manager. ```sh # pnpm pnpm add -D vite-plugin-tauri @tauri-apps/cli # yarn yarn add -D vite-plugin-tauri @tauri-apps/cli # npm npm i -D vite-plugin-tauri @tauri-apps/cli ``` -------------------------------- ### Running Tauri and Web Development Scripts Source: https://context7.com/amrbashir/vite-plugin-tauri/llms.txt These commands demonstrate how to run your web-only development server, the Tauri desktop application, build web assets, and create a cross-platform desktop installer. ```bash # Web only (no Tauri process spawned) pnpm dev # Desktop (Tauri window opens) pnpm dev:tauri # Build web assets only pnpm build # Build cross-platform desktop installer pnpm build:tauri ``` -------------------------------- ### Install vite-plugin-tauri and @tauri-apps/cli Source: https://context7.com/amrbashir/vite-plugin-tauri/llms.txt Install the plugin and Tauri CLI as development dependencies. Requires Node.js >= 14.6.0 and Vite >= 2. ```sh # pnpm (recommended) pnpm add -D vite-plugin-tauri @tauri-apps/cli # yarn yarn add -D vite-plugin-tauri @tauri-apps/cli # npm npm i -D vite-plugin-tauri @tauri-apps/cli ``` -------------------------------- ### Build production Tauri installer Source: https://context7.com/amrbashir/vite-plugin-tauri/llms.txt After Vite bundles the application, the plugin runs `tauri build` with the correct output directory configuration. ```sh # Produce a production Tauri installer pnpm build # => Vite builds to ./dist # => Plugin runs: tauri build --config '{"build":{"frontendDist":"../dist"}}' # => Tauri compiles Rust, bundles the app, and writes installers to src-tauri/target/release/bundle/ ``` -------------------------------- ### Run Vite + Tauri dev session Source: https://context7.com/amrbashir/vite-plugin-tauri/llms.txt Start the development server. The plugin automatically detects `tauri.conf.json` and runs `tauri dev` with the correct `devUrl`. If no Tauri project exists, it prompts to initialize one. ```sh # Start the Vite + Tauri dev session pnpm dev # => Vite starts on http://localhost:5173 # => Plugin detects tauri.conf.json # => Runs: tauri dev --config '{"build":{"devUrl":"http://localhost:5173"}}' # => The Tauri window opens showing the Vite dev server output # If no src-tauri/ exists yet, the plugin prompts: # ? Couldn't find a Tauri project in current directory, would you like to initialize a new one? (Y/n) # Answering Y runs: tauri init --app-name my-app --window-title "my-app window" ... ``` -------------------------------- ### Serve-mode hook Source: https://context7.com/amrbashir/vite-plugin-tauri/llms.txt This hook is applied during `vite dev`. It starts the Tauri CLI development process, injecting the correct dev URL at runtime. ```APIDOC ## Serve-mode hook — `vite-plugin-tauri:serve` ### Description Applied only during `vite dev`. Once the Vite HTTP server starts listening the plugin resolves the host and port, constructs the correct dev URL (`http://localhost:` or `https://` when TLS is enabled), and spawns `tauri dev --config '{"build":{"devUrl":"..."}}'`. If no Tauri project is found in the current directory tree, the user is prompted to initialise one. ### Usage ```sh # Start the Vite + Tauri dev session pnpm dev # => Vite starts on http://localhost:5173 # => Plugin detects tauri.conf.json # => Runs: tauri dev --config '{"build":{"devUrl":"http://localhost:5173"}}' # => The Tauri window opens showing the Vite dev server output # If no src-tauri/ exists yet, the plugin prompts: # ? Couldn't find a Tauri project in current directory, would you like to initialize a new one? (Y/n) # Answering Y runs: tauri init --app-name my-app --window-title "my-app window" ... ``` ``` -------------------------------- ### Advanced Vite Configuration with Separate Tauri Config Source: https://github.com/amrbashir/vite-plugin-tauri/blob/master/README.md Use a separate vite.config.tauri.js file to configure the tauri plugin, allowing for distinct development flows. This setup is useful for managing separate scripts in package.json. ```javascript import { defineConfig, mergeConfig } from "vite"; import baseViteConfig from "./vite.config"; import tauri from "vite-plugin-tauri"; export default defineConfig( mergeConfig(baseViteConfig, { plugins: [tauri()], // optional but recommended clearScreen: false, server: { open: false, }, }), ); ``` -------------------------------- ### Auto-initialisation of Tauri Project Source: https://context7.com/amrbashir/vite-plugin-tauri/llms.txt When the plugin cannot find a Tauri configuration file, it will prompt the user to scaffold a new Tauri project. It uses the nearest package.json's 'name' field for app and window titles. ```bash # Trigger scenario: run dev/build in a project without src-tauri/ pnpm dev:tauri # Terminal output: # ? Couldn't find a Tauri project in current directory, would you like to initialize a new one? (Y/n) # Y # Initializing Tauri... # [tauri init output …] # Tauri initialized. # The plugin then continues with dev/build normally. # Update src-tauri/tauri.conf.json as needed — the injected placeholders # are overridden at runtime by the plugin anyway. ``` -------------------------------- ### Configure vite-plugin-tauri in vite.config.ts Source: https://context7.com/amrbashir/vite-plugin-tauri/llms.txt Import and use the tauri plugin in your Vite configuration. Recommended settings for `clearScreen` and `server.open` are included. ```ts // vite.config.ts import { defineConfig } from "vite"; import tauri from "vite-plugin-tauri"; // default export // or: import { tauri } from "vite-plugin-tauri"; // named export export default defineConfig({ plugins: [ tauri(), // no required arguments; config param is reserved for future use ], // Recommended: prevent Vite from clearing the terminal (Tauri also logs here) clearScreen: false, server: { // Recommended: prevent Vite from opening a browser tab automatically open: false, }, }); ``` -------------------------------- ### Basic Vite Configuration Source: https://github.com/amrbashir/vite-plugin-tauri/blob/master/README.md Import and add the tauri plugin to your vite.config.js. It's recommended to disable screen clearing and auto-opening the server. ```javascript // vite.config.js import { defineConfig } from "vite"; import tauri from "vite-plugin-tauri"; // 1. import the plugin export default defineConfig({ plugins: [ tauri(), // 2. add it to the plugins list ], // 3. optional but recommended clearScreen: false, server: { open: false, }, }); ``` -------------------------------- ### tauri(config?) Source: https://context7.com/amrbashir/vite-plugin-tauri/llms.txt The main plugin factory function. It returns a Vite PluginOption array with hooks for serve and build modes. Both named and default exports are available. ```APIDOC ## tauri(config?) ### Description The single exported function `tauri()` returns a Vite `PluginOption` array containing two hooks: one for `serve` mode and one for `build` mode. Both exports (named and default) are available. ### Usage ```ts // vite.config.ts import { defineConfig } from "vite"; import tauri from "vite-plugin-tauri"; // default export // or: import { tauri } from "vite-plugin-tauri"; // named export export default defineConfig({ plugins: [ tauri(), // no required arguments; config param is reserved for future use ], // Recommended: prevent Vite from clearing the terminal (Tauri also logs here) clearScreen: false, server: { // Recommended: prevent Vite from opening a browser tab automatically open: false, }, }); ``` ``` -------------------------------- ### Build-mode hook Source: https://context7.com/amrbashir/vite-plugin-tauri/llms.txt This hook is applied during `vite build`. After Vite bundles the application, the plugin runs the Tauri CLI bundler. ```APIDOC ## Build-mode hook — `vite-plugin-tauri:build` ### Description Applied only during `vite build`. After Vite finishes writing the bundle (`closeBundle` hook), the plugin resolves the absolute output directory from `viteConfig.build.outDir`, computes a path relative to the Tauri config file, and runs `tauri build --config '{"build":{"frontendDist":"../dist"}}'` (or `distDir` for Tauri v1). ### Usage ```sh # Produce a production Tauri installer pnpm build # => Vite builds to ./dist # => Plugin runs: tauri build --config '{"build":{"frontendDist":"../dist"}}' # => Tauri compiles Rust, bundles the app, and writes installers to src-tauri/target/release/bundle/ ``` ``` -------------------------------- ### Set TAURI_PATH_DEPTH for Tauri config lookup Source: https://context7.com/amrbashir/vite-plugin-tauri/llms.txt Override the default directory depth for searching `tauri.conf.json` or `Tauri.toml` using the `TAURI_PATH_DEPTH` environment variable. ```sh # Default: search up to 3 levels deep pnpm dev # Custom depth: search up to 5 levels deep TAURI_PATH_DEPTH=5 pnpm dev # Equivalent inline for Windows (cross-env) npx cross-env TAURI_PATH_DEPTH=5 pnpm dev ``` -------------------------------- ### Passing Tauri CLI arguments Source: https://context7.com/amrbashir/vite-plugin-tauri/llms.txt Arguments after `-- -t` or `-- --tauri` are forwarded to the Tauri CLI. ```APIDOC ## Passing Tauri CLI arguments — `-- -t / --tauri` ### Description Any arguments after `-- -t` or `-- --tauri` in the npm/pnpm script invocation are forwarded directly to the Tauri CLI. This allows passing flags such as `--verbose`, `--release`, or `--target` without modifying `vite.config.ts`. ### Usage ```sh # Run Tauri dev with verbose logging pnpm dev -- -t --verbose # Build a release binary with a specific target pnpm build -- --tauri --target aarch64-apple-darwin # Run an arbitrary tauri subcommand (e.g., tauri info) pnpm dev -- -t info # Explicit dev + extra flags (plugin won't prepend "dev" if it's already present) pnpm dev -- --tauri dev --verbose --release ``` ``` -------------------------------- ### Separate Vite Config for Tauri Source: https://context7.com/amrbashir/vite-plugin-tauri/llms.txt Use this configuration when you need to keep your standard web development workflow separate from your Tauri desktop workflow. This prevents the normal web build from being cluttered with Tauri tooling. ```typescript // vite.config.tauri.ts import { defineConfig, mergeConfig } from "vite"; import baseViteConfig from "./vite.config"; import { tauri } from "vite-plugin-tauri"; export default defineConfig( mergeConfig(baseViteConfig, { plugins: [tauri()], clearScreen: false, server: { open: false, }, }), ); ``` ```json // package.json — add Tauri-specific scripts { "scripts": { "dev": "vite", // normal web dev "build": "vite build", // normal web build "dev:tauri": "vite --config vite.config.tauri.ts", // Tauri desktop dev "build:tauri": "vite build --config vite.config.tauri.ts" // Tauri desktop build } } ``` -------------------------------- ### TAURI_PATH_DEPTH Environment Variable Source: https://context7.com/amrbashir/vite-plugin-tauri/llms.txt Allows overriding the directory depth for searching `tauri.conf.json` or `Tauri.toml`. ```APIDOC ## TAURI_PATH_DEPTH environment variable — Tauri config lookup depth ### Description `getTauriConfPath()` uses `fast-glob` to search for `tauri.conf.json`, `tauri.conf.json5`, or `Tauri.toml` up to a configurable directory depth. The default depth is **3**. Override it with the `TAURI_PATH_DEPTH` environment variable when the Tauri project lives deeper in the folder tree. ### Usage ```sh # Default: search up to 3 levels deep pnpm dev # Custom depth: search up to 5 levels deep TAURI_PATH_DEPTH=5 pnpm dev # Equivalent inline for Windows (cross-env) npx cross-env TAURI_PATH_DEPTH=5 pnpm dev ``` ``` -------------------------------- ### Pass arguments to Tauri CLI Source: https://context7.com/amrbashir/vite-plugin-tauri/llms.txt Forward arguments to the Tauri CLI using `-- -t` or `-- --tauri` in npm/pnpm scripts for flags like `--verbose`, `--release`, or `--target`. ```sh # Run Tauri dev with verbose logging pnpm dev -- -t --verbose # Build a release binary with a specific target pnpm build -- --tauri --target aarch64-apple-darwin # Run an arbitrary tauri subcommand (e.g., tauri info) pnpm dev -- -t info # Explicit dev + extra flags (plugin won't prepend "dev" if it's already present) pnpm dev -- --tauri dev --verbose --release ``` -------------------------------- ### Pass Tauri CLI Arguments Source: https://github.com/amrbashir/vite-plugin-tauri/blob/master/README.md Pass arguments to the Tauri CLI by prefixing them with -- -t or --tauri. The -- is required to separate Vite and Tauri arguments. ```sh pnpm dev -- -t --verbose --release ``` -------------------------------- ### Modify package.json for Separate Tauri Scripts Source: https://github.com/amrbashir/vite-plugin-tauri/blob/master/README.md Add new scripts to package.json to run Vite with the separate Tauri configuration file. This enables dedicated commands for Tauri development and building. ```json // package.json { .. "scripts": { "dev": "vite", "build": "vite build", "dev:tauri": "vite --config vite.config.tauri.js", "build:tauri": "vite build --config vite.config.tauri.js", "preview": "vite preview" }, .. } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.