Skip to content

SonicGarden/next-csr-rewrites-generator

Repository files navigation

next-csr-rewrites-generator

Deploy helper command to generate rewrite rules for Next.js CSR application

Installation

yarn add @sonicgarden/next-csr-rewrites-generator

Usage

Add this command to your deployment script (The following is for deploying to firebase hosting)

package.json:

"scripts": {
  "deploy": "next build && next export && next-csr-rewrites-generate --format firebase && firebase deploy"
}

Note: of course, you can alos run this command manually!

Command usage

next-csr-rewrites-generate

  Deploy helper command to generate rewrite rules for Next.js CSR application 

Options

  -f, --format firebase   Format type                                                           
  -o, --output filepath   Output file path. (If omitted, the original file will be overwritten) 
  -h, --help              Show usage 

Generated hosting rewrite rules

When the following files exist in the deploy directory

index.html
hoge/[hogeId].html
fuga/[fugaId].html

The following rewrite rules will be added to firebase.json (cleanUrls will be added together)

{
  "hosting": {
    "rewrites": [
      {
        "source": "/hoge/:hogeId",
        "destination": "/hoge/[hogeId].html"
      },
      {
        "source": "/fuga/:fugaId",
        "destination": "/fuga/[fugaId].html"
      }
    ],
    "cleanUrls": true
  }
}

Note: rewrite rules other than dynamic routing will not be updated.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published