-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(#693): initial druxt-site update for @nuxt/kit
- Loading branch information
Showing
4 changed files
with
99 additions
and
94 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { addLayout, defineNuxtModule, installModule } from '@nuxt/kit' | ||
import { existsSync } from 'fs' | ||
import { resolve } from 'path' | ||
// import DruxtSiteStorybook from '../nuxtStorybook' | ||
|
||
/** | ||
* Nuxt module function to install Druxt Site. | ||
* | ||
* - Adds the DruxtSite component. | ||
* - Adds the core modules for DruxtJS Site. | ||
* - Adds default configuration for @nuxtjs/proxy. | ||
* - Enables Vuex store. | ||
* | ||
* @param {ModuleOptions} moduleOptions - The Nuxt.js module options. | ||
*/ | ||
const DruxtSiteNuxtModule = defineNuxtModule({ | ||
meta: { | ||
name: 'druxt-site', | ||
}, | ||
defaults: { | ||
baseUrl: '', | ||
endpoint: '/jsonapi' | ||
}, | ||
|
||
async setup(moduleOptions, nuxt) { | ||
// Prevent issue "FATAL: Cannot determine nuxt version! Is current | ||
// instance passed?". | ||
nuxt._version = nuxt._version || '2.' | ||
// This is required to prevent "FATAL: nuxt.options._layers is not iterable" | ||
// error when using `installModule()`. | ||
nuxt.options._layers = nuxt.options._layers || [] | ||
|
||
// Set default options. | ||
const options = { | ||
baseUrl: moduleOptions.baseUrl, | ||
...nuxt.options?.druxt, | ||
proxy: { | ||
api: false, | ||
files: true, | ||
...nuxt.options?.druxt?.proxy, | ||
}, | ||
site: { | ||
layout: true, | ||
...nuxt.options?.druxt?.site, | ||
...moduleOptions, | ||
}, | ||
} | ||
nuxt.options.druxt = options | ||
|
||
// Register components directories. | ||
nuxt.hook('components:dirs', dirs => { | ||
dirs.push({ path: resolve(__dirname, '../dist/components') }) | ||
}) | ||
|
||
// Add Druxt modules. | ||
const druxtModules = [ | ||
'druxt', | ||
'druxt-blocks', | ||
'druxt-breadcrumb', | ||
'druxt-entity', | ||
'druxt-menu', | ||
'druxt-router', | ||
'druxt-schema', | ||
'druxt-views' | ||
] | ||
for (const module of druxtModules) { | ||
await installModule(module, {}, nuxt) | ||
} | ||
|
||
// Add default layout. | ||
if (!(await existsSync(resolve(nuxt.options.srcDir, nuxt.options.dir.layouts))) && options.site.layout) { | ||
addLayout(resolve(__dirname, '../dist/layouts/default.vue'), 'default') | ||
} | ||
|
||
// Nuxt Storybook. | ||
// @TODO - @nuxt/kit and @nuxt/storybook aren't compatible. | ||
// this.nuxt.hook('storybook:config', async ({ stories }) => { | ||
// await DruxtSiteStorybook.call(this, { options, stories }) | ||
// }) | ||
} | ||
}) | ||
|
||
export default DruxtSiteNuxtModule | ||
|
||
/** | ||
* Module options object. | ||
* | ||
* @typedef {object} ModuleOptions | ||
* @see {@link ./typedefs/moduleOptions|ModuleOptions} | ||
*/ |
This file was deleted.
Oops, something went wrong.