manifest.json

app 目錄的 根目錄 下新增或生成一個符合 Web Manifest 規範manifest.(json|webmanifest) 檔案,以向瀏覽器提供有關您的網頁應用程式的資訊。

靜態 Manifest 檔案

app/manifest.json | app/manifest.webmanifest
{
  "name": "My Next.js Application",
  "short_name": "Next.js App",
  "description": "An application built with Next.js",
  "start_url": "/"
  // ...
}

生成 Manifest 檔案

新增一個回傳 Manifest 物件manifest.jsmanifest.ts 檔案。

小知識:manifest.js 是一種特殊的路由處理器 (Route Handlers),預設會被快取,除非它使用了 動態 API動態設定 選項。

import type { MetadataRoute } from 'next'

export default function manifest(): MetadataRoute.Manifest {
  return {
    name: 'Next.js App',
    short_name: 'Next.js App',
    description: 'Next.js App',
    start_url: '/',
    display: 'standalone',
    background_color: '#fff',
    theme_color: '#fff',
    icons: [
      {
        src: '/favicon.ico',
        sizes: 'any',
        type: 'image/x-icon',
      },
    ],
  }
}

Manifest 物件

Manifest 物件包含大量選項,這些選項可能會因新的網路標準而更新。如需瞭解所有當前選項的資訊,請參閱程式碼編輯器中的 MetadataRoute.Manifest 類型(如果使用 TypeScript),或查看 MDN 文件。

On this page