Configuration ​
Nuxt Tauri works out of the box with zero configuration, but you can customize its behavior if needed.
Default Configuration ​
The module automatically:
- Registers the plugin for Tauri API availability
- Auto-imports
useTauriInvokeanduseTauriEventcomposables - Provides TypeScript support
Module Options ​
Currently, the module doesn't require specific configuration options, but you can add the module to your nuxt.config.ts:
export default defineNuxtConfig({
modules: ["nuxt-module-tauri"],
// Optional: Module-specific configuration (future versions)
nuxtTauri: {
// Configuration options will be added in future versions
},
});Environment Detection ​
The composables automatically detect if they're running in a Tauri environment:
- In Tauri: Full functionality available
- In Browser: Graceful error handling with helpful error messages
<script setup>
const { data, error, execute } = useTauriInvoke("my_command");
// This will show an error in browser environment
// "Tauri API not available"
</script>TypeScript Configuration ​
For optimal TypeScript support, ensure your tsconfig.json includes:
{
"compilerOptions": {
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true
}
}Development vs Production ​
Development ​
During development, you can test your Tauri commands:
# Start Nuxt development server
npm run dev
# In another terminal, start Tauri
cargo tauri devProduction ​
For production builds, ensure both Nuxt and Tauri are built:
# Build Nuxt
npm run build
# Build Tauri app
cargo tauri buildTauri Commands Setup ​
On the Rust side, ensure your commands are properly exposed:
use tauri::command;
#[command]
fn get_user(id: u32) -> Result<User, String> {
// Your implementation
Ok(User {
id,
name: "John Doe".to_string(),
email: "john@example.com".to_string(),
})
}
fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![get_user])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}Auto-imports ​
The following composables are automatically available without imports:
useTauriInvokeuseTauriEvent
If you need to import them manually:
import { useTauriInvoke, useTauriEvent } from "#imports";Best Practices ​
Error Handling ​
Always handle errors gracefully:
<script setup>
const { data, error, pending, execute } = useTauriInvoke("risky_command");
watchEffect(() => {
if (error.value) {
console.error("Command failed:", error.value);
// Show user-friendly error message
}
});
</script>Type Safety ​
Use TypeScript interfaces for better development experience:
interface ApiResponse<T> {
success: boolean;
data: T;
message?: string;
}
interface User {
id: number;
name: string;
email: string;
}
const { data } = useTauriInvoke<ApiResponse<User>>("get_user", { id: 1 });Troubleshooting ​
Common Issues ​
"Tauri API not available" error: You're likely running in a browser environment. This is expected behavior.
Commands not found: Ensure your Rust commands are properly registered in the
invoke_handler.TypeScript errors: Make sure
@tauri-apps/apiis installed and up to date.