跳转到内容
Tauri

Next.js

Next.js 是一个用于 React 的元框架。更多关于 Next.js 的信息请访问 https://nextjs.net.cn。本指南截止到 Next.js 14.2.3 版本。

检查列表

  • 通过设置 output: 'export' 使用静态导出。Tauri 不支持基于服务器的解决方案。
  • tauri.conf.json 中,使用 out 目录作为 frontendDist

示例配置

  1. src-tauri/tauri.conf.json
    {
    "build": {
    "beforeDevCommand": "npm run dev",
    "beforeBuildCommand": "npm run build",
    "devUrl": "https://127.0.0.1:3000",
    "frontendDist": "../out"
    }
    }
  2. 更新 Next.js 配置
    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://nextjs.net.cn/docs/pages/building-your-application/deploying/static-exports
    output: 'export',
    // Note: This feature is required to use the Next.js Image component in SSG mode.
    // See https://nextjs.net.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;
  3. 更新 package.json 配置
    "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint",
    "tauri": "tauri"
    }

© 2025 Tauri 贡献者。CC-BY / MIT