Skip to content

Commit 22855bd

Browse files
feat: add vite documentation, clarify TAURI_DEV_HOST usage (#2761)
Co-authored-by: Tillmann <[email protected]>
1 parent 961c2de commit 22855bd

File tree

8 files changed

+129
-29
lines changed

8 files changed

+129
-29
lines changed

src/content/docs/develop/index.mdx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,19 @@ To open the mobile IDE instead of running on a connected device or simulator, us
160160
cargo="cargo tauri [android|ios] dev --open"
161161
/>
162162

163+
:::note
164+
If you intend on running the application on a physical iOS device you must also provide the `--host` argument
165+
and your development server must use the `process.env.TAURI_DEV_HOST` value as host.
166+
See your framework's setup guide for more information.
167+
168+
<CommandTabs
169+
npm="npm run tauri [android|ios] dev --open --host"
170+
yarn="yarn tauri [android|ios] dev --open --host"
171+
pnpm="pnpm tauri [android|ios] dev --open --host"
172+
cargo="cargo tauri [android|ios] dev --open --host"
173+
/>
174+
:::
175+
163176
:::caution
164177
To use Xcode or Android Studio the Tauri CLI process **must** be running and **cannot** be killed.
165178
It is recommended to use the `tauri [android|ios] dev --open` command and keep the process alive until you close the IDE.

src/content/docs/fr/start/frontend/trunk.mdx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ Vous devrez utiliser `cargo install --git https://github.com/amrbashir/trunk` po
1717

1818
- Utilisez SSG, Tauri ne supporte pas officielement les solutions basées sur un serveur.
1919

20-
- Utilisez `address = "0.0.0.0"` pour que le serveur web soit disponible sur le réseau pour le développement mobile.
2120
- Activez `withGlobalTauri` pour vous assurer que les APIs de Tauri sont disponibles dans la variable `window.__TAURI__` et peuvent être importées en utilisant `wasm-bindgen`.
2221

2322
## Exemple de configuration
@@ -45,7 +44,4 @@ Vous devrez utiliser `cargo install --git https://github.com/amrbashir/trunk` po
4544
# Trunk.toml
4645
[watch]
4746
ignore = ["./src-tauri"]
48-
49-
[serve]
50-
address = "0.0.0.0"
5147
```

src/content/docs/start/frontend/leptos.mdx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ Leptos is a Rust based web framework. You can read more about Leptos on their [o
1313
## Checklist
1414

1515
- Use SSG, Tauri doesn't officially support server based solutions.
16-
- Use `serve.address = "0.0.0.0"` so that the webserver is available on the network for mobile development.
1716
- Use `serve.ws_protocol = "ws"` so that the hot-reload websocket can connect properly for mobile development.
1817
- Enable `withGlobalTauri` to ensure that Tauri APIs are available in the `window.__TAURI__` variable and can be imported using `wasm-bindgen`.
1918

@@ -49,7 +48,6 @@ Leptos is a Rust based web framework. You can read more about Leptos on their [o
4948
ignore = ["./src-tauri"]
5049

5150
[serve]
52-
address = "0.0.0.0"
5351
port = 1420
5452
open = false
5553
ws_protocol = "ws"

src/content/docs/start/frontend/nuxt.mdx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Nuxt is a meta framework for Vue. Learn more about Nuxt at https://nuxt.com. Thi
1313
## Checklist
1414

1515
- Use SSG by setting `ssr: false`. Tauri doesn't support server based solutions.
16-
- Set host to `0.0.0.0`.
16+
- Use `process.env.TAURI_DEV_HOST` as the development server host IP when set to run on iOS physical devices.
1717
- Use `dist/` as `frontendDist` in `tauri.conf.json`.
1818
- Compile using `nuxi generate`.
1919
- (Optional): Disable telemetry by setting `telemetry: false` in `nuxt.config.ts`.
@@ -82,8 +82,8 @@ Nuxt is a meta framework for Vue. Learn more about Nuxt at https://nuxt.com. Thi
8282
devtools: { enabled: true },
8383
// Enable SSG
8484
ssr: false,
85-
// Enables the development server to be discoverable by other devices for mobile development
86-
devServer: { host: '0.0.0.0' },
85+
// Enables the development server to be discoverable by other devices when running on iOS physical devices
86+
devServer: { host: process.env.TAURI_DEV_HOST || 'localhost' },
8787
vite: {
8888
// Better support for Tauri CLI output
8989
clearScreen: false,
@@ -94,14 +94,6 @@ Nuxt is a meta framework for Vue. Learn more about Nuxt at https://nuxt.com. Thi
9494
server: {
9595
// Tauri requires a consistent port
9696
strictPort: true,
97-
hmr: {
98-
// Use websocket for mobile hot reloading
99-
protocol: 'ws',
100-
// Make sure it's available on the network
101-
host: '0.0.0.0',
102-
// Use a specific port for hmr
103-
port: 5183,
104-
},
10597
},
10698
},
10799
});

src/content/docs/start/frontend/trunk.mdx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ Trunk is a WASM web application bundler for Rust. Learn more about Trunk at http
1313
## Checklist
1414

1515
- Use SSG, Tauri doesn't officially support server based solutions.
16-
- Use `serve.address = "0.0.0.0"` so that the webserver is available on the network for mobile development.
1716
- Use `serve.ws_protocol = "ws"` so that the hot-reload websocket can connect properly for mobile development.
1817
- Enable `withGlobalTauri` to ensure that Tauri APIs are available in the `window.__TAURI__` variable and can be imported using `wasm-bindgen`.
1918

@@ -46,7 +45,6 @@ Trunk is a WASM web application bundler for Rust. Learn more about Trunk at http
4645
ignore = ["./src-tauri"]
4746

4847
[serve]
49-
address = "0.0.0.0"
5048
ws_protocol = "ws"
5149
```
5250

Lines changed: 113 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,121 @@
11
---
22
title: Vite
3-
sidebar:
4-
badge:
5-
text: Stub
6-
variant: caution
73
tableOfContents:
84
minHeadingLevel: 2
95
maxHeadingLevel: 5
106
---
117

12-
import Stub from '@components/Stub.astro';
8+
import { Tabs, TabItem, Steps } from '@astrojs/starlight/components';
139

14-
<Stub />
10+
Vite is a build tool that aims to provide a faster and leaner development experience for modern web projects.
11+
This guide is accurate as of Vite 5.4.8.
12+
13+
## Checklist
14+
15+
- Use `dist/` as `frontendDist` in `tauri.conf.json`.
16+
- Use `process.env.TAURI_DEV_HOST` as the development server host IP when set to run on iOS physical devices.
17+
18+
## Example configuration
19+
20+
<Steps>
21+
22+
1. ##### Update Tauri configuration
23+
24+
Assuming you have the following `dev` and `build` scripts in your `package.json`:
25+
26+
```json
27+
{
28+
"scripts": {
29+
"dev": "vite dev",
30+
"build": "vite build"
31+
}
32+
}
33+
```
34+
35+
You can configura the Tauri CLI to use your Vite development server and dist folder
36+
along with the hooks to automatically run the Vite scripts:
37+
38+
<Tabs>
39+
40+
<TabItem label="npm">
41+
42+
```json
43+
// tauri.conf.json
44+
{
45+
"build": {
46+
"beforeDevCommand": "npm run dev",
47+
"beforeBuildCommand": "npm run build",
48+
"devUrl": "http://localhost:5173",
49+
"frontendDist": "../dist"
50+
}
51+
}
52+
```
53+
54+
</TabItem>
55+
56+
<TabItem label="yarn">
57+
58+
```json
59+
// tauri.conf.json
60+
{
61+
"build": {
62+
"beforeDevCommand": "yarn dev",
63+
"beforeBuildCommand": "yarn build",
64+
"devUrl": "http://localhost:5173",
65+
"frontendDist": "../dist"
66+
}
67+
}
68+
```
69+
70+
</TabItem>
71+
72+
<TabItem label="pnpm">
73+
74+
```json
75+
// tauri.conf.json
76+
{
77+
"build": {
78+
"beforeDevCommand": "pnpm dev",
79+
"beforeBuildCommand": "pnpm build",
80+
"devUrl": "http://localhost:5173",
81+
"frontendDist": "../dist"
82+
}
83+
}
84+
```
85+
86+
</TabItem>
87+
88+
</Tabs>
89+
90+
1. ##### Update Vite configuration:
91+
92+
```js title="vite.config.js"
93+
import { defineConfig } from 'vite';
94+
95+
export default defineConfig({
96+
// prevent vite from obscuring rust errors
97+
clearScreen: false,
98+
server: {
99+
// Tauri expects a fixed port, fail if that port is not available
100+
strictPort: true,
101+
// if the host Tauri is expecting is set, use it
102+
host: host || false,
103+
port: 5173,
104+
},
105+
// to access the Tauri environment variables set by the CLI with information about the current target
106+
envPrefix: ['VITE_', 'TAURI_ENV_*'],
107+
build: {
108+
// Tauri uses Chromium on Windows and WebKit on macOS and Linux
109+
target:
110+
process.env.TAURI_ENV_PLATFORM == 'windows'
111+
? 'chrome105'
112+
: 'safari13',
113+
// don't minify for debug builds
114+
minify: !process.env.TAURI_ENV_DEBUG ? 'esbuild' : false,
115+
// produce sourcemaps for debug builds
116+
sourcemap: !!process.env.TAURI_ENV_DEBUG,
117+
},
118+
});
119+
```
120+
121+
</Steps>

src/content/docs/zh-cn/start/frontend/leptos.mdx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ Leptos 是一个基于 Rust 的 Web 框架。您可以在他们的[官方网站]
1313
## 检查清单
1414

1515
- 使用 SSG,Tauri 不支持基于服务器的解决方案。
16-
- 使用 `serve.address = "0.0.0.0"`,以使服务器在移动端开发时可用。
1716
- 使用 `serve.ws_protocol = "ws"` 以便进行移动开发时热重载 websocket 可以正常连接。
1817
- 启用 `withGlobalTauri` 以确保 Tauri API 在使用 `window.__TAURI__` 变量时可用,并且可以使用 `wasm-bindgen` 导入。
1918

@@ -49,7 +48,6 @@ Leptos 是一个基于 Rust 的 Web 框架。您可以在他们的[官方网站]
4948
ignore = ["./src-tauri"]
5049

5150
[serve]
52-
address = "0.0.0.0"
5351
port = 1420
5452
open = false
5553
ws_protocol = "ws"

src/content/docs/zh-cn/start/frontend/trunk.mdx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ Trunk 是一个用于 Rust 的 WASM 网络应用程序打包工具。要了解
1313
## 检查清单
1414

1515
- 使用 SSG。Tauri 不支持基于服务端的解决方案。
16-
- 使用 `address = "0.0.0.0"` 以使服务器在移动端开发时可用。
1716
- 使用 `ws_protocol = "ws"` 以便进行移动开发时热重载 websocket 可以正常连接。
1817
- 启用 `withGlobalTauri` 以确保 Tauri API 在使用 `window.__TAURI__` 变量时可用,并且可以使用 `wasm-bindgen` 导入。
1918

@@ -46,7 +45,6 @@ Trunk 是一个用于 Rust 的 WASM 网络应用程序打包工具。要了解
4645
ignore = ["./src-tauri"]
4746

4847
[serve]
49-
address = "0.0.0.0"
5048
ws_protocol = "ws"
5149
```
5250

0 commit comments

Comments
 (0)