Created
June 22, 2019 10:41
-
-
Save mornir/845c6de94b1877d9c33d9d8eb7ee6ca2 to your computer and use it in GitHub Desktop.
Merge preview and client sanity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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