用yarn构建一个Tauri应用

准备工作

安装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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值