跳至內容

manifest.json

app 目錄的根目錄中新增或產生符合 Web 資訊清單規範manifest.(json|webmanifest) 檔案,以便為瀏覽器提供有關您的 Web 應用程式的資訊。

靜態 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 是一種特殊的路由處理程式,預設會被快取,除非它使用 動態 API動態設定 選項。

app/manifest.ts
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 物件包含許多選項,這些選項可能會因為新的網路標準而更新。有關所有目前選項的資訊,如果您使用 TypeScript,請參考程式碼編輯器中的 MetadataRoute.Manifest 類型,或者參閱 MDN 文件。