Skip to content

The Plugin Ecosystem

Tauri v2 embraces a modular architecture. To keep the core application lightweight and secure, many features that were previously built-in (or features you might expect from Electron) are now separated into plugins. This ensures you only bundle code for the features you actually use.

Using a plugin generally involves three steps:

  • Install: Add the Rust crate via cargo and the JavaScript API via your package manager (npm/pnpm/yarn).
  • Register: Initialize the plugin in your Rust lib.rs builder chain.
  • Usage: Import the JavaScript API in your frontend to use the functionality.

The plugin-store allows you to save simple key-value data, like user preferences or application state, to a file on disk. It handles serialization automatically.

import { Store } from '@tauri-apps/plugin-store';
const store = new Store('settings.json');
// Set a value
await store.set('theme', 'dark');
// Save changes to disk
await store.save();
// Retrieve a value
const val = await store.get('theme');

The plugin-fs plugin provides access to the file system. Unlike standard browser APIs, this allows you to read and write files anywhere the OS permissions allow (scoped for security).

import { readTextFile, writeTextFile, BaseDirectory } from '@tauri-apps/plugin-fs';
// Write to the App Data directory
await writeTextFile('app.conf', 'config_data', {
baseDir: BaseDirectory.AppData
});
// Read the file back
const content = await readTextFile('app.conf', {
baseDir: BaseDirectory.AppData
});

While fetch works in the browser, it is restricted by CORS (Cross-Origin Resource Sharing). The plugin-http allows your Rust backend to perform the request, bypassing CORS issues entirely, which is essential for calling third-party APIs.

For more complex data needs, plugin-sql provides a connection to SQLite, MySQL, or PostgreSQL. SQLite is particularly popular for local desktop apps as it requires no server setup.

import Database from '@tauri-apps/plugin-sql';
const db = await Database.load('sqlite:test.db');
await db.execute('INSERT INTO users (name) VALUES ($1)', ['Alice']);

Plugins are the building blocks of a rich Tauri application, allowing you to extend functionality without bloating your application core.