Skip to content
Tauri 中文网

从 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@latest
npm run 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 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 #10437PR #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 环境变量是否匹配 androidios, 但由于现在除非使用 iOS 设备,否则我们可以连接到 localhost,因此你应该改为检查 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,
},
});

Tauri 中文网 - 粤ICP备13048890号
Nodejs.cn 旗下网站