Skip to content

Commit

Permalink
feat: disable cdn when enablePreview is called
Browse files Browse the repository at this point in the history
closes #45
  • Loading branch information
danielroe committed Jan 8, 2021
1 parent f5ab953 commit 137149a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
7 changes: 7 additions & 0 deletions docs/content/en/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ Add a global `<SanityContent>` component to display portable text. See [the docs

If you have `components: true` set in your `nuxt.config` file, then this helper will be registered with `@nuxt/components` and imported only where needed, rather than registered globally.

### `disableSmartCdn`

- Type: **boolean**
- Default: **`false`**

By default, if [Preview Mode](https://nuxtjs.org/docs/2.x/features/live-preview) 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**
Expand Down
7 changes: 7 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ export interface SanityModuleOptions extends Partial<SanityConfiguration> {
* @default true
*/
contentHelper?: boolean
/**
* Don't disable `useCdn` when preview mode is on
* https://nuxtjs.org/docs/2.x/features/live-preview/
*
* @default false
*/
disableSmartCdn?: boolean
/**
* Configuration for any additional clients
*/
Expand Down
5 changes: 4 additions & 1 deletion templates/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ const createSanity = options => ({
/**
* @type {import('@nuxt/types').Plugin}
*/
export default async ({ $config }, inject) => {
export default async (context, inject) => {
const { $config } = context
const options = defu($config && $config.sanity || {}, _options)

if (!options.disableSmartCdn && '$preview' in context) options.useCdn = false
const additionalClients = defu($config && $config.sanity && $config.sanity.additionalClients || {}, _additionalClients)

inject('sanity', {
Expand Down

0 comments on commit 137149a

Please sign in to comment.