What is Tauri

Tauri is a cross-platform Web-based client framework similar to Electron. Tauri allows you to run web sites on PC \ MAC in a local client way. So some functions that web sites cannot do, such as reading and storing local files, can be implemented through the API provided on Tauri.

Comparative electron advantage

  • Tauri’s packed execution file will be more than 100 megabytes smaller than Electron.
  • Electron uses the Chromium kernel, which causes a huge footprint, while Tauri uses WebView2 on Windows. Edge Chromium, which webview2 uses, has more advantages than Chromium.
  • These are the visible advantages, and you can check out the website for more

Tauri que

Environment Installation

Before Hello world, you need to install the environment, and since the Tauri framework is based on Rust, you need to install a C++ compiler. For details about the installation environment, see the official documentation

One thing to note here is that the nodejs path should not use Spaces or Chinese characters. If it is already installed, you need to change the path (including environment variables) or it will fail to run.

The official documentation environment must be fully installed, or the runtime will report an error that the specified file cannot be found.

Let’s have a nice Hello World

React is used as a web site. Create a React project by scaffolding Mr. Create-react app

npx create-react-app hello-tauri
Copy the code

After the project is generated, the corresponding tauri dependent library is added

yarn add -D @tauri-apps/cli
yarn add @tauri-apps/api
Copy the code

The dependency library installation will be slow without a ladder, so be patient.

Add scripts to package.json

"scripts": {
    "tauri": "tauri",
}
Copy the code

The Tauri environment is initialized

yarn tauri init
Copy the code

run

yarn start 
Copy the code

Start another CMD

yarn tauri dev
Copy the code

The effect

This is a demo program