准备工作
安装Rust以及其他系统依赖,见官网文档
创建应用
mkdir tauri-demo1
cd tauri-demo1
npm init -y
修改package.json的scripts内容
"scripts": {
"dev": "npx serve ui/",
"build": "",
"tauri": "tauri"
},
创建UI
mkdir ui
内容
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>文档</title>
</head>
<body>
<h1>这是来自 Tauri 的欢迎!</h1>
</body>
</html>
创建Rust工程
安装依赖工具
yarn add -D @tauri-apps/cli
初始化工程
yarn tauri init
默认填写
? What is your app name? › tauri-demo1
✔ What should the window title be? · 应用标题title1
✔ Where are your web assets (HTML/CSS/JS) located, relative to the "<current dir>/src-tauri/tauri.conf.json" file that will be created? · ../ui
✔ What is the url of your dev server? · ../ui
✔ What is your frontend dev command? · npm run dev
✔ What is your frontend build command? · npm run build
预览应用
yarn tauri dev
构建应用
yarn tauri build
错误
1.预览报错
$ C:\demo\tauri\tauri-demo1\node_modules\.bin\tauri dev
Running BeforeDevCommand (`npm run dev`)
Info Watching C:\demo\tauri\tauri-demo1\src-tauri for changes...
Updating crates.io index
npm ERR! Missing script: "dev"
npm ERR!
npm ERR! To see a list of scripts, run:
npm ERR! npm run
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\User\AppData\Local\npm-cache\_logs\2023-05-19T09_31_05_618Z-debug-0.log
Error The "beforeDevCommand" terminated with a non-zero status code.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
解决,修改package.json,添加scripts
"scripts": {
"dev": "npx serve ui/",
"build": "",
"tauri": "tauri"
},
2.构建报错
C:\demo\tauri\tauri-demo1〉yarn tauri build 05/19/2023 05:35:53 下午
yarn run v1.22.19
$ tauri build
Error You must change the bundle identifier in `tauri.conf.json > tauri > bundle > identifier`. The default value `com.tauri.dev` is not allowed as it must be unique across applications.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
修改tauri.conf.json
文件
"identifier": "com.tauri.dev",
修改为
"identifier": "com.sample.dev",
3. serve包不存在
可全局安装依赖包
npm i -g serve