tauri 打包现有React 项目(window)

注意事项:1.此项目没有路由,2.没有 API请求
环境配置 请看文档
tauri 文档
第一步:在需要打包的项目根目录执行命令

npm install --save-dev @tauri-apps/cli

第二步:在 package.json scripts 中添加 tauri

"scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "tauri": "tauri" //添加此代码
  },

第三步:在项目根目录 初始化 tauri ,一直回车就行,需要修改参数就在配置文件修改即可。

npm run tauri init

初始化完成 会出现一个 src-tauri的文件夹。
第四步: 启动项目执行命令

npm run tauri dev

注意事项:
1)如果出现如下错误

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\14991\AppData\Local\npm-cache\_logs\2023-02-18T02_04_03_466Z-debug-0.log
       Error The "beforeDevCommand" terminated with a non-zero status code.

原因是 在 tauri.conf.json 配置文件中 beforeDevCommand 参数 的 值错误,应该是React 项目 package.json 里的 项目启动命令。
例:我的是 “npm run start ”

 "scripts": {
    "start": "react-scripts start", //我的启动命令
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "tauri": "tauri"
  },

//修改后的 tauri.conf.json

"build": {
    "beforeBuildCommand": "npm run build",
    "beforeDevCommand": "npm run start", //修改后的值
    "devPath": "http://localhost:3000",
    "distDir": "../build"
  },

beforeBuildCommand 同理 记得修改
重新执行 npm run tauri dev (会下载一些包不要急,时间会挺长)
结果会出现一个窗口 成功
在这里插入图片描述
第四步打包:执行命令

npm run 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.
 解决 修改 tauri.conf.json 在文件中的 identifier参数,修改为非默认值。
 

重新执行命令(等待打包)
完成打包
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值