Sanity Configuration
Configuring Sanity as one or more of a site's content sources using the @stackbit/cms-sanity module.
Stackbit has a tight integration to support Sanity as a content source. This guide covers what you need to know about configuring Stackbit to provide a two-way data sync between your Sanity project(s).
Here is an example configuration that uses Next.js as the site framework and uses a page
content type to represent pages:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Notice the following:
SanityContentSource
is being loaded from the@stackbit/cms-sanity
which must be installed first. This package is not needed in your production site.- Sanity is being configured using local environment variables. Stackbit automatically loads a
.env
in the root of your project. - There is a content type with an ID of
page
that is being used to store page data in Sanity. That content type has a field with nameslug
that determines the URL path at which the page is made available.
Prerequisites
To be able to work with Sanity, you must first have the following:
- A Sanity project with content in a dataset.
- The proper API keys and related environment variables that can access your content. (See options below.)
Installed
@stackbit/cms-sanity
package as a development dependency. (We also recommend@stackbit/types
to help with configuration.)1
Usage
1
2
3
4
5
6
7
8
9
10
Options
Storing Sensitive Values
Sensitive values can be stored in a .env
file, which will then be available when the Stackbit configuration file is loaded.
1
2
3
Model Type Inference
The Sanity CSI module makes the following inferences:
- Object models in Sanity are automatically inferred as Stackbit
object
models. - Document models are inferred as Stackbit
data
models.
Therefore, page
models must be defined using the modelExtensions
property.