Next.js
Next.js 是 React 的元框架。在 https://next.nodejs.cn 了解有关 Next.js 的更多信息。本指南适用于 Next.js 14.2.3 版。
¥Next.js is a meta framework for React. Learn more about Next.js at https://next.nodejs.cn. This guide is accurate as of Next.js 14.2.3.
检查清单
¥Checklist
-
通过设置
output: 'export'
使用静态导出。Tauri 不支持基于服务器的解决方案。¥Use static exports by setting
output: 'export'
. Tauri doesn’t support server-based solutions. -
在
tauri.conf.json
中将out
目录用作frontendDist
。¥Use the
out
directory asfrontendDist
intauri.conf.json
.
示例配置
¥Example Configuration
-
src-tauri/tauri.conf.json {"build": {"beforeDevCommand": "npm run dev","beforeBuildCommand": "npm run build","devUrl": "http://localhost:3000","frontendDist": "../out"}}src-tauri/tauri.conf.json {"build": {"beforeDevCommand": "yarn dev","beforeBuildCommand": "yarn build","devUrl": "http://localhost:3000","frontendDist": "../out"}}src-tauri/tauri.conf.json {"build": {"beforeDevCommand": "pnpm dev","beforeBuildCommand": "pnpm build","devUrl": "http://localhost:3000","frontendDist": "../out"}}src-tauri/tauri.conf.json {"build": {"beforeDevCommand": "deno task dev","beforeBuildCommand": "deno task build","devUrl": "http://localhost:3000","frontendDist": "../out"}} -
Update Next.js configuration
next.conf.mjs const isProd = process.env.NODE_ENV === 'production';const internalHost = process.env.TAURI_DEV_HOST || 'localhost';/** @type {import('next').NextConfig} */const nextConfig = {// Ensure Next.js uses SSG instead of SSR// https://next.nodejs.cn/docs/pages/building-your-application/deploying/static-exportsoutput: 'export',// Note: This feature is required to use the Next.js Image component in SSG mode.// See https://next.nodejs.cn/docs/messages/export-image-api for different workarounds.images: {unoptimized: true,},// Configure assetPrefix or else the server won't properly resolve your assets.assetPrefix: isProd ? undefined : `http://${internalHost}:3000`,};export default nextConfig; -
Update package.json configuration
"scripts": {"dev": "next dev","build": "next build","start": "next start","lint": "next lint","tauri": "tauri"}
Tauri 中文网 - 粤ICP备13048890号