Open4

まだNext.js 13.4のApp routerで静的サイト作らない方がいい件について

チェチェチェチェ

App Routerで静的ページをビルド方法を調べてました。
next.config.jsで以下のように追記します。

/**
 * @type {import('next').NextConfig}
 */
const nextConfig = {
  output: 'export',
 
  // Optional: Change links `/me` -> `/me/` and emit `/me.html` -> `/me/index.html`
  trailingSlash: true,
 
  // Optional: Prevent automatic `/me` -> `/me/`, instead preserve `href`
  skipTrailingSlashRedirect: true,
 
  // Optional: Change the output directory `out` -> `dist`
  distDir: 'dist',
}
 
module.exports = nextConfig
$ npm run build

でdistフォルダーが生成されhtml/js/cssファイルが書き出されました。

https://nextjs.org/docs/app/building-your-application/deploying/static-exports#configuration

チェチェチェチェ

ただ、App Routerの静的ページ生成にはまだサポートしてない機能が多くあります。
https://nextjs.org/docs/app/building-your-application/deploying/static-exports#unsupported-features

今現在(2023/10/6 Next.js13.4の時点)サポートしてない内容はこちら

ダイナミックルートやリダイレクト、ミドルウェアなど、よく使われる機能がまだサポートされていないため、あの機能を入れた実装になるとビルド時にエラーになります。