跳到内容
Tauri

Next.js

Next.js 是一个用于 React 的元框架。在 https://nextjs.net.cn 了解更多关于 Next.js 的信息。本指南截至 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": "http://localhost: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 Contributors. CC-BY / MIT