Skip to content

Instantly share code, notes, and snippets.

@mornir
Created June 22, 2019 10:41
Show Gist options
  • Save mornir/845c6de94b1877d9c33d9d8eb7ee6ca2 to your computer and use it in GitHub Desktop.
Save mornir/845c6de94b1877d9c33d9d8eb7ee6ca2 to your computer and use it in GitHub Desktop.
Merge preview and client sanity
import Vue from 'vue'
import imageUrlBuilder from '@sanity/image-url'
import sanityClient from '@sanity/client'
function setUpSanity(isDraft = false) {
return sanityClient({
// Find your project ID and dataset in `sanity.json` in your studio project
projectId: process.env.SANITY_PROJECT_ID,
dataset: 'production',
useCdn: isDraft,
withCredentials: !isDraft,
})
}
// Get a pre-configured url-builder from your sanity client
const builder = imageUrlBuilder(setUpSanity())
Vue.prototype.$urlFor = source => builder.image(source).auto('format')
export default ({ app }, inject) => {
inject('sanity', setUpSanity)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment