Deploy helper command to generate rewrite rules for Next.js CSR application
yarn add @sonicgarden/next-csr-rewrites-generator
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!
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
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.