@tailwind base;
@tailwind components;
.btn {
@apply font-semibold text-white py-2 px-4 rounded;
}
@tailwind utilities;
not-found.js https://nextjs.org/docs/app/api-reference/file-conventions/not-found Next.js(13.4)のApp Routerで404ページをカスタムしつつタイトルなどのmetadataを変更する 4️⃣ - みかづきブログ・カスタム https://blog.kimizuka.org/entry/2023/06/22/235529
どう使うかの議論 Reusing Styles - Tailwind CSS https://tailwindcss.com/docs/reusing-styles#extracting-classes-with-apply
Install Tailwind CSS with Next.js - Tailwind CSS https://tailwindcss.com/docs/guides/nextjs
npx create-next-app@latest プロジェクト名 --typescript --eslint
(tailwindはNoを選択。)
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
prettier-plugin-tailwindcssインストールしたが、機能しない。
npm install -D prettier prettier-plugin-tailwindcss
eslint-plugin-tailwindcssインストール??
TailwindCSSを使う際に導入しておきたいPrettier, ESLint, VSCodeのプラグイン https://zenn.dev/dev_shun/articles/f3d4634a25cabf
/app/page.module.cssは不要なので削除
Tailwind CSS Cheat Sheet https://tailwindcomponents.com/cheatsheet/
tailwindでSASSを使う。
"editor.quickSuggestions": {
"strings": true
}
https://marketplace.visualstudio.com/items?itemName=csstools.postcss をインストールする方法があるが他のプラグインに影響するなど、評価がことごとく悪い。 vscodeで対象のcssを開き「言語モードの選択」でtailwindcssにすればOK。
VSCode で Tailwind CSS のクラス名を自動補完する拡張機能が便利です ++ Gaji-Laboブログ https://www.gaji.jp/blog/2022/02/14/9129/
今すぐTailwindでの開発を楽にするお手軽2ステップ https://zenn.dev/ikenohi/articles/df2bf0c990d99a
tailwind.config.jsテーマの設定、不要cssの削除、@applyでまとめる?
ウェブアプリ開発にTailwind CSSを導入してみた | techlab / baigie https://baigie.me/engineerblog/integrating-tailwind-css/
// Pages in Next.js are Server Components by default
export default function Page() {
return (
- 「サーバーのみ」パッケージの作成
server-only、まずパッケージをインストール
```bash
npm install server-only
export async function getData() { const res = await fetch('https://external-service.com/data', { headers: { authorization: process.env.API_KEY, }, })
return res.json() }
client-onlyもあるみたい。
"use client" は Server Component と Client Component の境界につけよう
https://zenn.dev/luvmini511/articles/ec0e874a2cc1f1
use clientは境界となるファイルに一回だけつけるのが良い。use client は、すべてのファイルで定義する必要はありません。クライアント・モジュールの境界は、インポートされたすべてのモジュールがクライアント・コンポーネントとみなされるために、"エントリーポイント "で一度だけ定義する必要があります。
# layout
- 親レイアウトとその子の間でデータを受け渡すことはできません。
- レイアウトは現在のルート セグメントにアクセスできません。ルート セグメントにアクセスするには、クライアント コンポーネントでuseSelectedLayoutSegmentまたはuseSelectedLayoutSegmentsを使用できます。
- レイアウトのグループ化:(フォルダ名)を使うとセグメント(URL)を生成しなくなる。
- 複数ルートレイアウトの作成。app/layoutを削除し各ルートにlayoutを作成する(html/bodyタグもここに)
# template
ルート間で持続して状態を維持するレイアウトとは異なり、テンプレートはナビゲーション上の各子に対して新しいインスタンスを作成します。これは、ユーザーがテンプレートを共有するルート間を移動すると、コンポーネントの新しいインスタンスがマウントされ、DOM 要素が再作成され、状態は保持されず、エフェクトが再同期されることを意味します。
これらの特定の動作が必要な場合は、レイアウトよりもテンプレートの方が適切なオプションとなる場合があります。例えば:
- CSS またはアニメーション ライブラリを使用してアニメーションを開始/終了します。
- useEffect(ページ ビューのログ記録など) およびuseState(ページごとのフィードバック フォームなど)に依存する機能。
# metadata
https://nextjs.org/docs/app/api-reference/functions/generate-metadata
robotsやogなど。faviconは?
# LinkとuseRouter()
router.prefetchができない?
プリフェッチは開発環境では有効ではなく、運用環境でのみ有効になります。
# ルートグループ()とダイナミックルート[]
generateStaticParams()
サーバー関数。セグメントのパラメータを生成する。ビルド時に静的にルートを生成する。
自動的にメモ化される。
https://nextjs.org/docs/app/building-your-application/caching#request-memoization
```ts
export async function generateStaticParams() {
const posts = await fetch('https://.../posts').then((res) => res.json())
return posts.map((post) => ({
slug: post.slug,
}))
}
https://nextjs.org/docs/app/building-your-application/routing/loading-ui-and-streaming page.jsファイルとその下にある子は自動的に境界で囲まれます(Suspense)。 推奨事項とのこと。
// Suspenseの例
import { Suspense } from 'react'
import { PostFeed, Weather } from './Components'
export default function Posts() {
return (
<section>
<Suspense fallback={<p>Loading feed...</p>}>
<PostFeed />
</Suspense>
<Suspense fallback={<p>Loading weather...</p>}>
<Weather />
</Suspense>
</section>
)
}
以降流し読み。
https://nextjs.org/docs/app/building-your-application/optimizing/fonts
https://nextjs.org/docs/app/building-your-application/optimizing/metadata
https://nextjs.org/docs/app/api-reference/file-conventions/metadata
OG,JSON-LD,ファビコン ,robots, sitemap.xmlなど
https://nextjs.org/docs/app/building-your-application/configuring/eslint
https://nextjs.org/docs/app/building-your-application/deploying
https://nextjs.org/docs/app/api-reference/components/image
avif/webpサポート
https://nextjs.org/docs/app/api-reference/file-conventions/layout
Pagesとは異なり、Layout コンポーネントはpropを受け取りません
https://nextjs.org/docs/app/api-reference/file-conventions/metadata/app-icons
favicon.icoイメージはapp/ の最上位レベルにのみ配置できます。
https://nextjs.org/docs/app/api-reference/file-conventions/metadata/sitemap 静的なものしか置けない?動的ルーティングの場合はどうするのか。ファイル分割は今のところできない。
https://nextjs.org/docs/app/api-reference/functions/use-selected-layout-segment
呼び出し元のレイアウトの1 レベル下のアクティブなルート セグメントを読み取ることができるクライアント コンポーネントフックです。
これは、アクティブな子セグメントに応じてスタイルが変更される親レイアウト内のタブなどのナビゲーション UI に役立ちます。 アクティブリンクなど。
https://nextjs.org/docs/app/api-reference/functions/use-selected-layout-segments
ブレッドクラムなどのアクティブな子セグメントの知識が必要な親レイアウトで UI を作成する場合に役立ちます。
next.cofig.jsでリダイレクト可能