从 Tauri 2.0 Beta 升级
本指南引导你将 Tauri 2.0 测试版应用升级到 Tauri 2.0 候选版本。
¥This guide walks you through upgrading your Tauri 2.0 beta application to Tauri 2.0 release candidate.
自动迁移
¥Automated Migration
Tauri v2 CLI 包含一个 migrate
命令,该命令可自动执行大部分流程并帮助你完成迁移:
¥The Tauri v2 CLI includes a migrate
command that automates most of the process and helps you finish the migration:
npm install @tauri-apps/cli@latestnpm run tauri migrate
yarn upgrade @tauri-apps/cli@latestyarn tauri migrate
pnpm update @tauri-apps/cli@latestpnpm tauri migrate
cargo install tauri-cli --version "^2.0.0" --lockedcargo tauri migrate
了解有关 命令行接口参考 中 migrate
命令的更多信息
¥Learn more about the migrate
command in the Command Line Interface reference
重大更改
¥Breaking Changes
从测试版到候选版本,我们经历了几次重大变化。这些可以自动迁移(见上文)或手动执行。
¥We have had several breaking changes going from beta to release candidate. These can be either auto-migrated (see above) or manually performed.
Tauri 核心插件
¥Tauri Core Plugins
我们改变了 Tauri 内置插件在 PR #10390 功能中的处理方式。
¥We changed how Tauri built-in plugins are addressed in the capabilities PR #10390.
要从最新的测试版迁移,你需要在功能的所有核心权限标识符前面加上 core:
,或者切换到 core:default
权限并删除旧的核心插件标识符。
¥To migrate from the latest beta version you need to prepend all core permission identifiers in your capabilities with core:
or switch to the core:default
permission and remove old core plugin identifiers.
..."permissions": [ "path:default", "event:default", "window:default", "app:default", "image:default", "resources:default", "menu:default", "tray:default",]...
..."permissions": [ "core:path:default", "core:event:default", "core:window:default", "core:app:default", "core:image:default", "core:resources:default", "core:menu:default", "core:tray:default",]...
我们还添加了一个新的特殊 core:default
权限集,它将包含所有核心插件的所有默认权限,因此你可以简化功能配置中的权限样板。
¥We also added a new special core:default
permission set which will contain all default permissions of all core plugins, so you can simplify the permissions boilerplate in your capabilities config.
..."permissions": [ "core:default"]...
内置开发服务器
¥Built-In Development Server
我们对内置开发服务器 PR #10437 和 PR #10456 的网络暴露进行了更改。
¥We introduced changes to the network exposure of the built-in development server PR #10437 and PR #10456.
内置移动开发服务器不再暴露网络范围,而是将流量从本地机器直接隧道传输到设备。
¥The built-in mobile development server no longer exposes network wide and tunnels traffic from the local machine directly to the device.
目前,此改进在 iOS 设备上运行(直接或从 Xcode)时不会自动应用。在这种情况下,我们默认使用开发服务器的公共网络地址,但有一种解决方法,即打开 Xcode 自动启动 macOS 机器和连接的 iOS 设备之间的连接,然后运行 tauri ios dev --force-ip-prompt
选择 iOS 设备的 TUN 地址(以 ::2 结尾)。
¥Currently this improvement does not automatically apply when running on iOS devices (either directly or from Xcode).
In this case we default to using the public network address for the development server,
but there’s a way around it which involves opening Xcode to automatically start a connection between your macOS machine and your connected iOS device,
then running tauri ios dev --force-ip-prompt
to select the iOS device’s TUN address (ends with ::2).
如果打算在物理 iOS 设备上运行,则你的开发服务器配置需要适应此更改。以前我们建议检查 TAURI_ENV_PLATFORM
环境变量是否与 android
或 ios
匹配,但由于我们现在可以连接到 localhost,除非使用 iOS 设备,因此你应该检查 TAURI_DEV_HOST
环境变量。以下是 Vite 配置迁移的示例:
¥Your development server configuration needs to adapt to this change if running on a physical iOS device is intended.
Previously we recommended checking if the TAURI_ENV_PLATFORM
environment variable matches either android
or ios
,
but since we can now connect to localhost unless using an iOS device, you should instead check the TAURI_DEV_HOST
environment variable.
Here’s an example of a Vite configuration migration:
- 2.0.0-beta:
import { defineConfig } from 'vite';import { svelte } from '@sveltejs/vite-plugin-svelte';import { internalIpV4Sync } from 'internal-ip';
const mobile = !!/android|ios/.exec(process.env.TAURI_ENV_PLATFORM);
export default defineConfig({ plugins: [svelte()], clearScreen: false, server: { host: mobile ? '0.0.0.0' : false, port: 1420, strictPort: true, hmr: mobile ? { protocol: 'ws', host: internalIpV4Sync(), port: 1421, } : undefined, },});
- 2.0.0:
import { defineConfig } from 'vite';import Unocss from 'unocss/vite';import { svelte } from '@sveltejs/vite-plugin-svelte';
const host = process.env.TAURI_DEV_HOST;
export default defineConfig({ plugins: [svelte()], clearScreen: false, server: { host: host || false, port: 1420, strictPort: true, hmr: host ? { protocol: 'ws', host: host, port: 1430, } : undefined, },});
:::note 注意
不再需要 internal-ip
NPM 包,你可以直接使用 TAURI_DEV_HOST 值。
¥The internal-ip
NPM package is no longer required, you can directly use the TAURI_DEV_HOST value instead.
:::
Tauri 中文网 - 粤ICP备13048890号