Provisioning Sanity

Using the import configuration property to provision Sanity when duplicating a GitHub repository.

This is only relevant when creating a Stackbit project by duplicating a GitHub repository.

You don't need Sanity provisioning if you have already set up a Sanity project for your project, or if you plan to manually create and configure a project.

Stackbit will handle provisioning a new Sanity project, along with the initial payload of models and content when creating a new project by duplicating a GitHub repository.

Exporting Content from Sanity

In most cases, projects that can be provisioned with Sanity as a content source have a Sanity project as the source of truth for duplicated projects.

The first step in preparing your project to be duplicated is to export the content schema and the initial site contents from your Sanity project.

Be sure to configure the export to include a compressed file of all appropriate schemas, documents, and assets. Commit the exported data file to your project. See here for an example.

Here is an export script we often use in Sanity projects. It generates a export.tar.gz file, like the one found in our Sanity starter.

Import Configuration

Once you've exported the content (and committed the data file), all that is left to do is add configuration for importing the content during the provisioning process.

The following properties should be added to an import property in your Stackbit configuration file. All properties are required and are strings, unless otherwise noted.

contentFile
Path relative to the root of the project, pointing to the file that contains the exported data. This should be compressed (typically something like export.tar.gz)
datasetEnvVar
A string representing the name of the environment variable that specifies the dataset to which the imported content should be added. This is not the name of the dataset, but the name of the environment variable.
deployGraphql
(boolean) Set to true to ensure that Stackbit deploys Sanity GraphQL API when creating the site.
deployStudio
(boolean) Set to true to ensure that Stackbit deploys Sanity Studio when creating the site.
projectIdEnvVar
A string representing the name of the environment variable that contains the Sanity project ID. This is not the project ID itself, but the name of the environment variable.
sanityStudioPath
Path to the studio directory, relative to the root of the project.
tokenEnvVar
A string representing the name of the environment variable that contains the Sanity API access token. This is not the token itself, but the name of the environment variable.
type
Set to sanity.
  • 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
export default {
  contentSources: [
    new SanityContentSource({
      rootPath: __dirname,
      studioPath: path.join(__dirname, 'studio'),
      studioUrl: '',
      projectId: process.env.SANITY_PROJECT_ID,
      token: process.env.SANITY_ACCESS_TOKEN,
      dataset: process.env.SANITY_DATASET || 'production',
    }),
  ],
  mapModels: ({ models }) => {
    // page definitions and model decorations ...
  },
  import: {
    contentFile: 'sanity-export/export.tar.gz',
    datasetEnvVar: 'SANITY_DATASET',
    deployGraphql: false,
    deployStudio: true,
    projectIdEnvVar: 'SANITY_PROJECT_ID',
    sanityStudioPath: 'studio',
    tokenEnvVar: 'SANITY_ACCESS_TOKEN',
    type: 'sanity',
  },
  // other properties ...
}