Giter Site home page Giter Site logo

next-js-directory's Introduction

Next.js のディレクトリ構成について

前提

  • next.js のバージョンは 12 を想定

構成

.
├── components
│   ├── elements
│   │   └── utils
│   ├── layouts
│   └── page
├── config
├── const
├── docs
├── hooks
├── libs
├── pages
├── public
├── stores
├── test
├── types
└── utils
   ├── api
   │   ├── del
   │   ├── get
   │   ├── post
   │   └── put
   └── auth

components

  • アプリケーション全体で使うコンポーネントを置く
  • components/elements
    • components/layoutscomponents/page で使うコンポーネントを置く
  • components/elements/utils
    • アプリケーション全体で使う共通コンポーネントを置く
  • components/layouts
    • アプリケーション全体で使うレイアウトコンポーネントを置く
    • Header・Footer・管理者や一般ユーザーなどによってレイアウトを出し分ける Layout コンポーネントを置く
  • components/page
    • components/elementscomponents/layouts を組み合わせたコンポーネントを置く
    • pages からは components/page のコンポーネントを読み込むだけ使える形にしたものを置く

config

  • アプリケーション全体の設定を置く
  • 主に CSS フレームワークの設定やライブラリの設定などを置く

const

  • アプリケーション全体の定数を置く

docs

  • 開発時の注意事項、アイデアを置く

hooks

  • react のカスタムフックを置く

libs

  • ライブラリ固有のコード、ラッパー、初期化や設定のコードなど、データ取得に絡まないコードを置く
  • ライブラリ毎に切り替わる可能性もあるので、ライブラリごとにディレクトリを分ける

pages

  • Next のページコンポーネントを置く

public

  • 静的ファイルを置く

stores

  • アプリケーション全体のグローバルステート、データフェッチライブラリの管理に使う設定を置く

test

  • テストコードを置く

types

  • type、interface を置く

utils

  • グローバルで使える関数を置く
  • utils/api
    • HTTP リクエストを置く
    • 必要であれば、各 HTTP リクエストディレクトリの中をページごとにディレクトリを分ける
  • utils/auth
    • 認証系の処理を置く

参考

next-js-directory's People

Contributors

leeddhh avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.