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?

More than 3 years have passed since last update.

Next.js+Firebase Hostingでブログ構築

Last updated at Posted at 2022-08-15

Next.js+Firebase Hostingでブログ構築しました。今後はこちらに投稿します。。

ブログ
ソース

参考にさせていただいた情報

Next.jsでのブログ立ち上げ

ssgでnext/imageを使うとビルドエラー
→imgを使うか、ここを参考にする

Next.jsでページ共通の処理をする

React-playerがHydration errorを出す
→react-playerをdynamic importする

import dynamic from 'next/dynamic'
const ReactPlayer = dynamic(() => import("react-player"), { ssr: false });

Firebase Hostingにデプロイするときの注意点

・出力ディレクトリはoutを指定
・next.config.jsにtrailingSlash: trueを追加
・scriptsに"export": "next export"を追加

package.json
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint",
    "export": "next export"
  },

・ビルド→エクスポート→デプロイという流れで行う。これを自動化するにはfirebase.jsonを修正すればいい。firebase.jsonのhostingの下に"predeploy": "npm run build && npm run export",を追加。

firebase.json
{
  "hosting": {
    "predeploy": "npm run build && npm run export",
    "site": "<app名>",
    "public": "out",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ]
  }
}

そして、

firebase deploy --only hosting:<app名>

でデプロイ

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?