{"id":15441112,"url":"https://github.com/zdenham/next-static-utils","last_synced_at":"2025-04-13T15:40:36.254Z","repository":{"id":243170974,"uuid":"810459376","full_name":"zdenham/next-static-utils","owner":"zdenham","description":"Tooling to host Next.js websites with app router statically","archived":false,"fork":false,"pushed_at":"2024-06-25T05:34:29.000Z","size":56,"stargazers_count":46,"open_issues_count":3,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-10-18T12:17:44.904Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zdenham.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-04T18:32:27.000Z","updated_at":"2024-10-15T20:27:52.000Z","dependencies_parsed_at":"2024-06-07T05:36:21.182Z","dependency_job_id":"0738e763-c961-45a7-940a-aea3719c21ec","html_url":"https://github.com/zdenham/next-static-utils","commit_stats":{"total_commits":38,"total_committers":1,"mean_commits":38.0,"dds":0.0,"last_synced_commit":"311b050c40898fefb7eea15b4e172a5c447d0958"},"previous_names":["zdenham/next-static-utils"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zdenham%2Fnext-static-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zdenham%2Fnext-static-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zdenham%2Fnext-static-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zdenham%2Fnext-static-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zdenham","download_url":"https://codeload.github.com/zdenham/next-static-utils/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248739757,"owners_count":21154222,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-01T19:16:38.585Z","updated_at":"2025-04-13T15:40:36.232Z","avatar_url":"https://github.com/zdenham.png","language":"TypeScript","readme":"\u003cp align=\"center\"\u003e\n  \u003cb style=\"font-size: 20px\"\u003e\n    ⚡️ Next Static Utils ⚡️\n  \u003c/b\u003e\n  \u003cbr/\u003e\n  Utilities to host your next.js app as a static site wherever your heart desires\u003cbr/\u003e\n  Including dynamic routes and app router support\n\u003c/p\u003e\n\n# Example\n\nCheck out the example [repo](https://github.com/zdenham/next-static-aws-example) and the live [demo site](https://defn0rdp54dhd.cloudfront.net).\n\n## Motivation\n\nNext.js offers an option for [static site generation](https://nextjs.org/docs/pages/building-your-application/rendering/static-site-generation), which allows you to export your site as raw html, js, etc... and host it statically on a CDN, or however you like! This reduces the infra overhead of your application, if you are willing to sacrifice SSR features.\n\n**But SSG does not work with dynamic routes unless you generate all pages at build time**. There are some discussions around this issue [here](https://github.com/vercel/next.js/discussions/55393#discussioncomment-9668219) and [here](https://github.com/vercel/next.js/discussions/64660#discussioncomment-9667981), which the Vercel team will hopefully resolve soon. But even so, most static hosting providers outside of Vercel don't know how to handle the way next.js does code splitting out of the box, which can lead to unwanted 404 errors.\n\nNext Static Utils aims to provide workarounds and utilities to address some of these issues and make hosting your next.js site statically **anywhere** you darn well please a bit more enjoyable. \n\nStarting with support for AWS S3 + Cloudfront, but can presumably add other providers relatively easily.\n\n# Set Up\n\n### Installation And CLI\n\n```bash\npnpm install next-static-utils\n...\n# Generates edge function for re-routing to a fallback page for dynamic params\npnpm next-static-utils generate [cloudfront|serve]\n```\n\n### Usage\n\nOn your dynamic page:\n\n```javascript\nimport { withDynamicParams } from 'next-static-utils';\n\n// creates fallback parameter page\nexport const generateStaticParams = withDynamicParams();\n```\n\nTo use the dynamic paramaters:\n\n```javascript\n'use client';\n\nimport { useDynamicParams } from 'next-statis-utils';\n\nexport default function Component() {\n  // pulls params from the url, e.g. /users/:id\n  const { id } = useDynamicParams();\n\n  return (\n    \u003cdiv\u003e\n      Hello\n    \u003c/div\u003e\n  )\n}\n```\n\n### Recommended Next Config\n\n```javascript\nexport default (phase) =\u003e {\n  const nextConfig = {\n    output: phase === 'phase-production-build' ? 'export' : 'standalone',\n  };\n  return nextConfig;\n};\n```\n\n## Who its for\n\n- If you want to host your next.js app statically, **particularly using AWS S3 and Cloudfront and still use app router**\n- If you have a separate backend and don't want high infra overhead or vendor lock-in for your front end hosting\n- If you are **not** concerned about SEO, or powerful rich previews and open graph\n- If you tend to fetch data client side after the initial page load and do **not** intend to utilize Next.js's SSR features\n\nPrivate / auth gated applications, admin dashboards, simple tools, blogs \u0026 content sites with a relatively small catalog can all work.\n\n## How it works\n\nFor every dynamic route, next static utils generates a fallback page which is served for dynamic routes, this also satisfies next.js's requirement to generate static params when using the `output: export` option.\n\nInstead of using `useParams` which is not supported in SSG mode, the params are provided with a new hook `useDynamicParams`\n\nThe CLI also generates a cloudfront function to properly handle re-routing at an edge function level in AWS.\n\n## Other Cool / Related Projects\n\n- [next-nginx-routes](https://github.com/geops/next-nginx-routes) helps host your next.js static site using nginx routes\n- [SSG](https://ssg.dev) is great if you want to host on AWS, but with a more robust infrastructure\n\n## TODO\n\n- [ ] support partial static generation at build time\n- [ ] GCloud support?\n- [ ] terraform script to deploy via cli\n- [ ] S3 static hosting rewrites support\n- [ ] Move to using routes.manifest instead of iterating over app directory?\n- [ ] Github pages support?","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzdenham%2Fnext-static-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzdenham%2Fnext-static-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzdenham%2Fnext-static-utils/lists"}