forked from tauri-apps/tauri-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
i18(zh-cn): Synchronizing content (tauri-apps#2231)
Co-authored-by: DK Liao <[email protected]>
- Loading branch information
Showing
4 changed files
with
224 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,103 +1,118 @@ | ||
--- | ||
title: Next.js | ||
i18nReady: true | ||
tableOfContents: | ||
minHeadingLevel: 2 | ||
maxHeadingLevel: 5 | ||
--- | ||
|
||
import { Tabs, TabItem } from '@astrojs/starlight/components'; | ||
import { Tabs, TabItem, Steps } from '@astrojs/starlight/components'; | ||
import CommandTabs from '@components/CommandTabs.astro'; | ||
|
||
Next.js 是一个 React 框架。在 https://nextjs.org 获取更多有关 Next.js 的信息。本指南基于 Next.js 13.4.19。 | ||
Next.js 是一个基于 React 的元框架。要了解更多关于 Next.js 的信息,请访问 https://nextjs.org 。本指南适用于 Next.js 14.2.3 版本。 | ||
|
||
## 检查清单 | ||
|
||
- 设置 `output: 'export'` 以启用静态导出。Tauri 不支持服务端渲染方案。 | ||
- 为了移动端通用性,使用 `internal-ip`,因此你可以配置 `assetPrefix`。这是服务器正确解析资产文件所必需的。 | ||
- 在 `tauri.conf.json` 中,使用 `out/` 作为 `distDir`。 | ||
- 通过设置 `output: 'export'` 来使用静态导出。Tauri 不支持基于服务器的解决方案。 | ||
- 使用 `internal-ip` 以实现移动设备兼容性,这样您就可以配置 `assetPrefix`。这是必需的,以便服务器正确解析资源。 | ||
- 在 `tauri.conf.json` 中将 `frontendDist` 设置为 `out/`。 | ||
|
||
## 示例配置 | ||
|
||
1. 安装 `internal-ip` 以用于移动端开发: | ||
|
||
<CommandTabs | ||
npm="npm install --save-dev internal-ip" | ||
yarn="yarn add -D internal-ip" | ||
pnpm="pnpm add -D internal-ip" | ||
/> | ||
|
||
2. 更新 Tauri 配置: | ||
|
||
<Tabs> | ||
<TabItem label="npm"> | ||
|
||
```json | ||
// tauri.conf.json | ||
{ | ||
"build": { | ||
"beforeDevCommand": "npm run dev", | ||
"beforeBuildCommand": "npm run build", | ||
"devPath": "http://localhost:3000", | ||
"distDir": "../dist" | ||
} | ||
} | ||
``` | ||
|
||
</TabItem> | ||
<TabItem label="yarn"> | ||
|
||
```json | ||
// tauri.conf.json | ||
{ | ||
"build": { | ||
"beforeDevCommand": "yarn dev", | ||
"beforeBuildCommand": "yarn generate", | ||
"devPath": "http://localhost:3000", | ||
"distDir": "../dist" | ||
} | ||
} | ||
``` | ||
|
||
</TabItem> | ||
<TabItem label="pnpm"> | ||
|
||
```json | ||
// tauri.conf.json | ||
{ | ||
"build": { | ||
"beforeDevCommand": "pnpm dev", | ||
"beforeBuildCommand": "pnpm generate", | ||
"devPath": "http://localhost:3000", | ||
"distDir": "../dist" | ||
} | ||
} | ||
``` | ||
|
||
</TabItem> | ||
</Tabs> | ||
|
||
3. 更新 Next.js 配置: | ||
|
||
```ts | ||
// next.conf.ts | ||
const isProd = process.env.NODE_ENV === 'production'; | ||
module.exports = async (phase, { defaultConfig }) => { | ||
let internalHost = null; | ||
// 在开发模式下,我们使用 internal-ip 提供资产 | ||
if (!isProd) { | ||
const { internalIpV4 } = await import('internal-ip'); | ||
internalHost = await internalIpV4(); | ||
} | ||
const nextConfig = { | ||
// 确保 Next.js 使用 SSG 而不是 SSR | ||
// https://nextjs.org/docs/pages/building-your-application/deploying/static-exports | ||
output: 'export', | ||
// 注意:在 SSG 模式下使用 NextJS Image 需要此实验功能。 | ||
// 查阅 https://nextjs.org/docs/messages/export-image-api 以获得不同的解决方案。 | ||
images: { | ||
unoptimized: true, | ||
}, | ||
// 配置 assetPrefix,否则服务器将无法正确解析你的资产。 | ||
assetPrefix: isProd ? null : `http://${internalHost}:3000`, | ||
}; | ||
return nextConfig; | ||
}; | ||
``` | ||
<Steps> | ||
|
||
1. ##### 安装 `internal-ip` 版本 7 以进行移动端开发。 | ||
|
||
版本 8.0.0 **无法**运作! | ||
|
||
<CommandTabs | ||
npm="npm install --save-dev [email protected]" | ||
yarn="yarn add -D [email protected]" | ||
pnpm="pnpm add -D [email protected]" | ||
/> | ||
|
||
1. ##### 更新 Tauri 配置 | ||
|
||
<Tabs> | ||
|
||
<TabItem label="npm"> | ||
|
||
```json | ||
// src-tauri/tauri.conf.json | ||
{ | ||
"build": { | ||
"beforeDevCommand": "npm run dev", | ||
"beforeBuildCommand": "npm run build", | ||
"devUrl": "http://localhost:3000", | ||
"frontendDist": "../dist" | ||
} | ||
} | ||
``` | ||
|
||
</TabItem> | ||
|
||
<TabItem label="yarn"> | ||
|
||
```json | ||
// src-tauri/tauri.conf.json | ||
{ | ||
"build": { | ||
"beforeDevCommand": "yarn dev", | ||
"beforeBuildCommand": "yarn generate", | ||
"devUrl": "http://localhost:3000", | ||
"frontendDist": "../dist" | ||
} | ||
} | ||
``` | ||
|
||
</TabItem> | ||
|
||
<TabItem label="pnpm"> | ||
|
||
```json | ||
// src-tauri/tauri.conf.json | ||
{ | ||
"build": { | ||
"beforeDevCommand": "pnpm dev", | ||
"beforeBuildCommand": "pnpm generate", | ||
"devUrl": "http://localhost:3000", | ||
"frontendDist": "../dist" | ||
} | ||
} | ||
``` | ||
|
||
</TabItem> | ||
|
||
</Tabs> | ||
|
||
1. ##### 更新 Next.js 配置 | ||
|
||
```ts | ||
// next.conf.mjs | ||
/** @type {import('next').NextConfig} */ | ||
const isProd = process.env.NODE_ENV === 'production'; | ||
|
||
let internalHost = null; | ||
|
||
if (!isProd) { | ||
const { internalIpV4 } = await import('internal-ip'); | ||
internalHost = await internalIpV4(); | ||
} | ||
|
||
const nextConfig = { | ||
// 确保 Next.js 使用 SSG 而不是 SSR | ||
// https://nextjs.org/docs/pages/building-your-application/deploying/static-exports | ||
output: 'export', | ||
// 注意:在 SSG 模式下使用 Next.js 的 Image 组件需要此功能。 | ||
// 请参阅 https://nextjs.org/docs/messages/export-image-api 了解不同的解决方法。 | ||
images: { | ||
unoptimized: true, | ||
}, | ||
// 配置 assetPrefix,否则服务器无法正确解析您的资产。 | ||
assetPrefix: isProd ? null : `http://${internalHost}:3000`, | ||
}; | ||
|
||
export default nextConfig; | ||
``` | ||
|
||
</Steps> |
Oops, something went wrong.