nishimura.clubnishimura.club

Next.jsでsitemap.xmlを作る

作成日
2021-06-05
更新日
2021-06-05

iamvishnusankar/next-sitemapを使う。

インストール

yarn add next-sitemap -D

next-sitemap.js作成

next-sitemap.jsをプロジェクトルートに配置する。 staticサイトの場合、outに吐き出されるので、outDir: './out'に設定する。 (Static HTML Exportで確認)

module.exports = { siteUrl: 'https://example.com', generateRobotsTxt: true, sitemapSize: 7000, outDir: './out' }

build設定

package.jsonを変更する。

... "scripts": { "build": "next build && next export", "postbuild": "next-sitemap" // 追記 } ...

Related