0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

個人的備忘録:Next.js設定ファイル(next.config.ts)の理解を深めるために整理してみた

Posted at

はじめに

Next.js プロジェクトでは、next.config.ts というファイルに設定を書きます。
今回は、基本のテンプレートになっている下記の内容を解説します。

import type { NextConfig } from "next";

const nextConfig: NextConfig = {
  /* config options here */
};

export default nextConfig;

個人の備忘録程度の走り書きとなっておりますが、温かい目で見守っていただければ幸いです。

実際のファイルについて


1. import type { NextConfig } from "next";

  • Next.jsの標準タイプ NextConfig をインポートしています。
  • ここでは "type" だけをインポートしているので、実行時には消えます。
  • "設定オブジェクトの形をNext.jsの規則に合わせる"ための仕掛けです。

2. const nextConfig: NextConfig = { /* config options here */ };

  • nextConfigという 定数 を作成しています。
  • その型をさっきの NextConfigにしています。
  • 今はまだ空ですが、ここに各種設定を書き込んでいきます。

例:よく使うオプション

const nextConfig: NextConfig = {
  reactStrictMode: true,  // ReactのStrictModeを有効化
  images: {
    domains: ['example.com'],  // 画像を許可するドメイン
  },
};

3. export default nextConfig;

  • 最後に、この nextConfig外部で使えるようエクスポート しています。
  • Next.js本体が読み込めるようになり、ビルドや起動に適用されます。

まとめ

この next.config.tsは:

  • Next.jsの設定を
  • 正しい型 (NextConfig) に合わせて
  • 外部に提供する

ための「テンプレート」のようなものです。

今は空のままですが、ここに設定を追加することで自分のNext.jsアプリをカスタマイズできるようになります!

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?