Hosting Sanity + Next.js Project on Vercel - Monorepo or One Project?

2 replies
Last updated: Feb 23, 2021
I am new to the field. May I ask how should I host sanity and the nextjs web through vercel? Should I do it in monorepo or should I host it in one project? I have tried to host it in one project, however I am completely puzzled on how to do that as it seems there isn't a guide for it and when I read through many github projects that host both the web and sanity in the same project, the configuration method seems to differ from project to project. Thanks for any help!
Feb 23, 2021, 3:47 AM
Hi and welcome, Harry. I personally take the monorepo approach and I believe in most cases, Sanity does too. In fact, in this article Knut links to a list of monorepo pros and cons that you could consider.
To start off, you’ll need to have installed the CLI. If you haven’t already, run
npm i -g @sanity/cli
.
Here’s how I get set up. I create my project folder, then in it I add two folders:
sanity
and
web
. Call them what you wish. I go to the sanity folder and run
sanity init
, which creates a project. I usually choose the clean schema and then add in my own boilerplate, but you can choose whichever you think will best get you started. At this point, your Sanity project should be ready to go. You could run
sanity start
and start working in the Studio, but I would normally get the rest set up first.
In
web
you can set up however you choose. You’re planning to work with Next.js, so you can follow the steps (
create-next-app
or however you get started).
Once you’re set up, go to your project folder (containing
sanity
and
web
) and initialize your git repo. Make sure you have
.gitignore
files set up so you’re not committing node_modules and other ignorables. I’ll assume you’re deploying to GitHub but GitLab, BitBucket, or even a third-party repo should work, too.
I deploy all my studios to Sanity, which simply requires a
sanity deploy
command. Everything is committed to my GitHub repo but is accessible from
https://<name>.sanity.studio
.
For your front end, go to
vercel.com and choose New Project. Import the repo you created and committed to, and then when you get to the Import Project screen, select
web
(or whatever you called it). Vercel should automatically detect your framework and set your build settings.
If you run into any struggles, please post back here.
Feb 23, 2021, 5:32 AM
Thank you very much for your reply!
Feb 23, 2021, 5:53 AM

Sanity.io – build remarkable experiences at scale

Sanity is a customizable solution that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.