Skip to content

Commit

Permalink
Add injectClient to disable client injection
Browse files Browse the repository at this point in the history
  • Loading branch information
weotch committed May 5, 2022
1 parent ff6fc82 commit 1fa1404
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Set these properties within `cloak: { craft: { ... } }` in the nuxt.config.js:
- `pageTypenames` - An array of GraphQL typenames of Craft entry types whose URIs should be generated as pages. For example: `['towers_tower_Entry']`. Defaults to `[]`.
- `generateRedirects` - If true, adds redirect to the `static/_redirects` file using a `redirects` Craft section.
- `mocks` - An array of objects for use with [`mockAxiosGql`](https://github.com/BKWLD/cloak-utils/blob/main/src/axios.js).
- `injectClient` - Boolean for whether to inject the `$craft` client globally. Defaults to `true`. You would set this to `false` when this module is a depedency of another module (like [@cloak-app/algolia](https://github.com/BKWLD/cloak-algolia)) that is creating `$craft` a different way.

## Usage

Expand Down
5 changes: 4 additions & 1 deletion nuxt.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default function() {
setDefaultOptions(this, 'craft', {
generateRedirects: false,
pageTypenames: [],
injectClient: true,
})

// Set default options
Expand All @@ -34,7 +35,9 @@ export default function() {
// Add the Craft plugin which creates the Craft instance of Axios. Not using
// this.addPlugin so I don't have to deal with adding sub-imports via
// addTemplate.
this.options.plugins.unshift(join(__dirname, 'plugins/craft-client.js'))
if (this.options.cloak.craft.injectClient) {
this.options.plugins.unshift(join(__dirname, 'plugins/craft-client.js'))
}

// Support mocking
requireOnce(this, join(__dirname, './modules/mock-craft.js'))
Expand Down

0 comments on commit 1fa1404

Please sign in to comment.