Configuration


By default, @nuxtjs/sanity will look for a ~~/cms/sanity.config.ts file relative to your project's root directory, and it will read your projectId and dataset from there.

sanity.config.ts
import { defineConfig } from 'sanity'

export default defineConfig({
  projectId: '<sample-project-id>',
  dataset: 'production',
  // rest of your configuration
})

If you need to provide additional configuration, you can pass in an object in your Nuxt config with key details:

nuxt.config.ts
export default defineNuxtConfig({
  modules: ['@nuxtjs/sanity'],
  sanity: {
    projectId: 'myProject',
    apiVersion: '2021-10-18'
  },
})

Runtime configuration

It is also possible to pass options to this module through runtime configuration, via a sanity key. If you do so they will be merged with (and override) any other options passed in.

For example:

nuxt.config.ts
export default defineNuxtConfig({
  modules: ['@nuxtjs/sanity'],
  runtimeConfig: {
    sanity: {
      token: process.env.NUXT_SANITY_TOKEN,
    },
  },
  sanity: {
    projectId: 'myProject',
  },
})

Reference

globalHelper

  • Type: boolean
  • Default: false

Whether to provide a global $sanity helper that you can use throughout your project. (It's recommended not to do this but to use the useSanity and useSanityQuery composables.)

projectId

  • Required
  • Type: string

Your Sanity Project ID, which you can find in your Sanity dashboard.

Sanity dashboard

dataset

  • Type: string
  • Default: 'production'

apiVersion

  • Type: string
  • Default: '1'

You can specify the Sanity API version to use. More info here.

token

  • Type: string

You can provide a token or leave blank to be an anonymous user. (You can also set a token programmatically in a Nuxt plugin.)

withCredentials

  • Type: boolean
  • Default: false

Include credentials in requests made to Sanity. Useful if you want to take advantage of an existing authorisation to the Sanity CMS.

useCdn

  • Type: boolean
  • Default: true in production or false if a token has been passed in

minimal

  • Type: boolean
  • Default: false

Use an ultra-minimal Sanity client for making requests (a fork of picosanity with SSR-specific changes). It only supports fetch requests, but will significantly decrease your bundle size.

If you don't have @sanity/client installed, then @nuxtjs/sanity will use the minimal client by default.

disableSmartCdn

  • Type: boolean
  • Default: false

By default, if Preview Mode has been switched on, useCdn will be disabled. If this behaviour isn't desirable, you can disable it by setting { disableSmartCdn: false }.

additionalClients

  • Type: Object
  • Default: {}

You can create additional clients. Each client's name will be the key of the object provided, and the options provided will be merged with the options of the default client.

The options that can be provided are:

  • projectId
  • dataset
  • token
  • withCredentials
  • useCdn

So, for example:

nuxt.config.ts
export default defineNuxtConfig({
  modules: ['@nuxtjs/sanity'],
  sanity: {
    additionalClients: {
      another: {
        projectId: 'anotherproject',
      },
    },
  },
})

visualEditing

  • Type: Object
  • Default: undefined

Used to enable and configure Visual Editing. See the Visual Editing section for more details.