Provisioning Contentful

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

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

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

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

Exporting Content from Contentful

In most cases, projects that can be provisioned with Contentful as a content source have a Contentful space 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 Contentful space.

Be sure to configure the exports to include content types, entries, and to download assets. This will place your exported data in a new directory located wherever you ran the export command. Place this directory and its contents in your project and commit the files to Git.

Import Configuration

Once you've exported the content (and committed the data files), 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.

assetsDirectory

Set this to the directory containing your exported content, not the path to exported assets. The contentFile contains paths relative to this directory, which Stackbit will use to upload assets into the new space.

Note: This property can be ignored if uploadAssets is set to false.

contentFile
Path to the export.json file provided by the Contentful export.
deliveryTokenEnvVar
A string representing the name of the environment variable that contains the API delivery token that can be used to retrieve content from Contentful. This is not the token itself, but the name of the environment variable.
previewTokenEnvVar
A string representing the name of the environment variable that contains the API preview token that can be used to retrieve content from Contentful. This is not the token itself, but the name of the environment variable.
spaceIdEnvVar
A string representing the name of the environment variable that contains the Contentful space ID. This is not the space ID itself, but the name of the environment variable.
type
Set to contentful.
uploadAssets
(boolean) Whether exported assets should be uploaded. This is typically true when you're base space included asset entries.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
export default {
  contentSources: [
    new ContentfulContentSource({
      spaceId: process.env.CONTENTFUL_SPACE_ID,
      environment: process.env.CONTENTFUL_ENVIRONMENT,
      previewToken: process.env.CONTENTFUL_PREVIEW_TOKEN,
      accessToken: process.env.CONTENTFUL_MANAGEMENT_TOKEN,
    }),
  ],
  models: {
    // page definitions and model decorations ...
  },
  import: {
    type: 'contentful',
    contentFile: 'contentful/export.json',
    uploadAssets: true,
    assetsDirectory: 'contentful',
    spaceIdEnvVar: 'CONTENTFUL_SPACE_ID',
    deliveryTokenEnvVar: 'CONTENTFUL_DELIVERY_TOKEN',
    previewTokenEnvVar: 'CONTENTFUL_PREVIEW_TOKEN',
  },
  // other properties ...
}