package.jsonに export
と deploy
コマンドを追加
package.json
・・・
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"export": "next export",
"deploy": "yarn run build && yarn run export"
},
・・・
deploy
コマンドを実行すると /out/
にビルドしたファイルが書き出されるようになります。
![outフォルダにビルドしたファイルが書き出される](/img/article-images/deploy-next-to-netlify/01.jpg)
Netlifyでプロジェクトを作成する
Netlifyで「Create a new site」を実行
「Basic Build Settings」に
- Build command・・
yarn run deploy
- Publish directory・・
out
を設定。
![netlifyのプロジェクト作成時にyarn run deployを設定](/img/article-images/deploy-next-to-netlify/02.jpg)
この状態でDeploy Siteを押下します。
Netlifyでビルドの設定を変更する
既にNetlifyにプロジェクトを紐付けている場合は、
Settings > Build&Deploy
のBuild settingsの「Edit settings」から変更します。
![既存のプロジェクトの場合はEdit settingsから変更](/img/article-images/deploy-next-to-netlify/03.jpg)
- Build command・・
yarn run deploy
- Publish directory・・
out