-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathnuxtModule.js
57 lines (51 loc) · 1.6 KB
/
nuxtModule.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { join, resolve } from 'path'
/**
* The Nuxt.js module function.
*
* - Adds the Vue.js components to the Nuxt.js frontend.
*
* The module function should not be used directly, but rather installed via yout Nuxt.js configuration file.
*
* Options are set on the root level `druxt` Nuxt.js config object.
*
* @example <caption>nuxt.config.js</caption> @lang js
* module.exports = {
* modules: [
* 'druxt-breadcrumb'
* ],
* druxt: {
* baseUrl: 'https://example.com'
* }
* }
*
* @param {object} moduleOptions - Nuxt.js module options object.
*/
const DruxtBreadcrumbModule = async function (moduleOptions = {}) {
// Set default options.
const options = {
baseUrl: moduleOptions.baseUrl,
...(this.options || {}).druxt || {},
breadcrumb: {
...((this.options || {}).druxt || {}).breadcrumb,
...moduleOptions,
}
}
// Add dependent module.
await this.addModule(['druxt', options])
await this.addModule(['druxt-router/nuxt', options])
// Register components directories.
this.nuxt.hook('components:dirs', dirs => {
dirs.push({ path: join(__dirname, 'components') })
dirs.push({ path: join(__dirname, 'components/blocks') })
})
// Nuxt Storybook.
this.nuxt.hook('storybook:config', ({ stories }) => {
this.addTemplate({
src: resolve(__dirname, '../templates/druxt-breadcrumb.stories.js'),
fileName: 'stories/druxt-breadcrumb.stories.js',
})
stories.push(resolve(this.options.buildDir, './stories/druxt-breadcrumb.stories.js'))
})
}
DruxtBreadcrumbModule.meta = require('../package.json')
export { DruxtBreadcrumbModule }