Next.js
Next.js is a React framework. Learn more about Next.js at https://nextjs.org. This guide is accurate as of Next.js 13.4.19.
- Use static exports by setting
output: 'export'
. Tauri doesn’t support server-based solutions. - Use
internal-ip
for mobile compatibility so you can configureassetPrefix
. This is required so that the server properly resolves assets. - Use
out/
asdistDir
intauri.conf.json
.
- Install
internal-ip
for mobile development:
npm install --save-dev internal-ip
yarn add -D internal-ip
pnpm add -D internal-ip
- Update Tauri configuration:
{ "build": { "beforeDevCommand": "npm run dev", "beforeBuildCommand": "npm run build", "devPath": "http://localhost:3000", "distDir": "../dist" }}
{ "build": { "beforeDevCommand": "yarn dev", "beforeBuildCommand": "yarn generate", "devPath": "http://localhost:3000", "distDir": "../dist" }}
{ "build": { "beforeDevCommand": "pnpm dev", "beforeBuildCommand": "pnpm generate", "devPath": "http://localhost:3000", "distDir": "../dist" }}
- Update Next.js configuration:
const isProd = process.env.NODE_ENV === 'production';module.exports = async (phase, { defaultConfig }) => { let internalHost = null; // In dev mode we use the internal-ip to serve the assets if (!isProd) { const { internalIpV4 } = await import('internal-ip'); internalHost = await internalIpV4(); } const nextConfig = { // Ensure Next.js uses SSG instead of SSR // https://nextjs.org/docs/pages/building-your-application/deploying/static-exports output: 'export', // Note: This experimental feature is required to use NextJS Image in SSG mode. // See https://nextjs.org/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 ? null : `http://${internalHost}:3000`, }; return nextConfig;};
© 2024 Tauri Contributors. CC-BY / MIT