Skip to content

Commit

Permalink
feat: allow using runtimeConfig to set sanity options
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Aug 21, 2020
1 parent 027f1ea commit 8657d48
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions templates/plugin.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
import Vue from 'vue'
import defu from 'defu'

<%= options.client
? "import createClient from '@sanity/client'"
: "import { createClient } from '@nuxtjs/sanity'"
%>

<% if (options.components.imageHelper) { %>
import { SanityImage } from './sanity-image'
Vue.component('SanityImage', SanityImage)
import { SanityImage } from './sanity-image'
Vue.component('SanityImage', SanityImage)
<% } %>

<% if (options.components.contentHelper) { %>
import { SanityContent } from '@nuxtjs/sanity/dist/sanity-content'
Vue.component('SanityContent', SanityContent)
import { SanityContent } from '@nuxtjs/sanity/dist/sanity-content'
Vue.component('SanityContent', SanityContent)
<% } %>

const options = JSON.parse('<%= options.sanityConfig %>')
const _options = JSON.parse('<%= options.sanityConfig %>')

/**
* @type {import('@nuxt/types').Plugin}
*/
export default async (_ctx, inject) => {
export default async ({ $config }, inject) => {
const options = defu($config.sanity || {}, _options)
inject('sanity', {
client: createClient(options),
fetch(...args) {
Expand Down

0 comments on commit 8657d48

Please sign in to comment.