跳到內容

manifest.json

新增或產生一個 manifest.(json|webmanifest) 檔案,其符合 Web Manifest 規範app 目錄的根目錄中,以提供關於你的網頁應用程式的資訊給瀏覽器。

靜態 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.jsmanifest.ts 檔案,其回傳一個 Manifest 物件

须知: 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 物件包含大量的選項,這些選項可能會因為新的網路標準而更新。關於所有當前選項的資訊,請參考你在程式碼編輯器中使用的 MetadataRoute.Manifest 類型 (如果你使用 TypeScript) 或查看 MDN 文件。