- https://nextjs.org/docs
- ディレクトリの構成はこのようになる
project-root
├ pages
│ └ index.js(option)
├ .gitignore
└ package.json
- ディレクトリツリーの作成に使用 https://codogue.com/asciitree/
- node.jsを入れる!
- プロジェクトディレクトリを作る
- npm init
- npm install next react react-dom
- package.jsonの編集
- scriptを以下のように書き換える
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
}
- mainを削除
- pagesディレクトリを作成
- npx next build でビルド
- npx next start でサーバーの起動
- .vscode/にlaunch.jsonやtasks.jsonを作成
- launch.json
{ "version": "0.2.0", "configurations": [ { "type": "node", "request": "attach", "name": "debugger", "skipFiles": [ "<node_internals>/**" ], "port": 9229, "preLaunchTask" : "npm: dev - nextjs-blog" } ] }
- tasks.json
{ "version": "2.0.0", "tasks": [ { "type": "npm", "script": "build", "path": "nextjs-blog/", "group": "build", "problemMatcher": [], "label": "npm: build - nextjs-blog", "detail": "next build" }, { "type": "npm", "script": "dev", "path": "nextjs-blog/", "problemMatcher": [], "label": "npm: dev - nextjs-blog", "detail": "next dev", "group": { "kind": "build", "isDefault": true },"dependsOn" : [ "npm: build - nextjs-blog" ] } ] }
- .gitignoreを作成
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# next.js
/.next/
/out/
# production
/build
# misc
.DS_Store
*.pem
# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local
# vercel
.vercel
- npm install --save-dev @types/react
- npx tsc --init