跳到内容

manifest.json

在 `app` 目录的**根目录**中添加或生成一个符合 Web Manifest 规范 的 `manifest.(json|webmanifest)` 文件,为浏览器提供有关您的 Web 应用程序的信息。

静态清单文件

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.js` 或 `manifest.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',
      },
    ],
  }
}

清单对象

清单对象包含大量可能因新的网络标准而更新的选项。有关所有当前选项的信息,如果使用 TypeScript,请参阅代码编辑器中的 `MetadataRoute.Manifest` 类型,或参阅 MDN 文档。