Get a peek at our latest innovations at Sanity Product Day on Dec 8th →

How to Deploy a Static Site Generator

3 replies
Last updated: Mar 29, 2021

Hi! I was curious what methods people use to deploy their sites with a static site generator (in my case, Next.js). I want the production site to be static, but have a non-static version to do previews. We host the production site on S3, but can likely host a preview site elsewhere, if needed.
Anyone have thoughts/examples of workflows (drafts, webhooks, etc.) that people use to control when things go to prod while also allowing for edited content to be previewed?

(also, not sure if this channel is the right place for this -- lmk and thanks!)

Mar 8, 2021, 7:45 PM

Thanks

user U
! The site I'm building is fully static -- pulls from Sanity at build time + exports all the static assets, so I don't need the serverless stuff, but I appreciate the info.

Mar 9, 2021, 8:53 PM

That makes sense -- I think what makes sense for my usecase is to host the production site statically, but have a staging instance hosted either with serverless functs or as a node server to allow for preview! Mostly writing this out since I've been looking all around this Slack for various solutions to problems, so maybe someone will stumble on this one haha

Mar 10, 2021, 4:29 PM

You met the same problem as me. React-query is being used. This is my solution.


1. Build/Deploy CI after merging into preview branch
2.
https://react-query.tanstack.com/guides/ssr react-query options

{ enabled: process.env.MODE === 'preview' ? true : false }
3. sanity client env

{
  projectId: 'some-project-id',
  dataset: 'my-dataset',
  useCdn: process.env.MODE === 'preview' ? false : true
}

Mar 29, 2021, 4:13 AM

Sanity.io: Get the most out of your content

Sanity.io is a platform to build websites and applications. It comes with great APIs that let you treat content like data. Free to get started, and pay-as-you-go on all plans. Find out more.