feat: custom layouts directory

This commit is contained in:
Ricardo Gobbo de Souza 2018-02-03 16:41:43 -02:00
parent 536aab6380
commit b3f2a67793
5 changed files with 19 additions and 6 deletions

View File

@ -271,8 +271,8 @@ module.exports = class Builder {
} }
// -- Layouts -- // -- Layouts --
if (existsSync(resolve(this.options.srcDir, 'layouts'))) { if (existsSync(resolve(this.options.srcDir, this.options.dir.layouts))) {
const layoutsFiles = await glob('layouts/**/*.{vue,js}', { const layoutsFiles = await glob(`${this.options.dir.layouts}/**/*.{vue,js}`, {
cwd: this.options.srcDir, cwd: this.options.srcDir,
ignore: this.options.ignore ignore: this.options.ignore
}) })
@ -297,7 +297,7 @@ module.exports = class Builder {
if (!templateVars.components.ErrorPage && hasErrorLayout) { if (!templateVars.components.ErrorPage && hasErrorLayout) {
templateVars.components.ErrorPage = this.relativeToBuild( templateVars.components.ErrorPage = this.relativeToBuild(
this.options.srcDir, this.options.srcDir,
'layouts/error.vue' `${this.options.dir.layouts}/error.vue`
) )
} }
} }
@ -639,11 +639,11 @@ module.exports = class Builder {
watchFiles() { watchFiles() {
const src = this.options.srcDir const src = this.options.srcDir
let patterns = [ let patterns = [
r(src, 'layouts'), r(src, this.options.dir.layouts),
r(src, 'store'), r(src, 'store'),
r(src, 'middleware'), r(src, 'middleware'),
r(src, 'layouts/*.{vue,js}'), r(src, `${this.options.dir.layouts}/*.{vue,js}`),
r(src, 'layouts/**/*.{vue,js}') r(src, `${this.options.dir.layouts}/**/*.{vue,js}`)
] ]
if (this._nuxtPages) { if (this._nuxtPages) {
patterns.push( patterns.push(

View File

@ -286,6 +286,7 @@ Options.defaults = {
}, },
dir: { dir: {
assets: 'assets', assets: 'assets',
layouts: 'layouts',
pages: 'pages', pages: 'pages',
static: 'static' static: 'static'
}, },

View File

@ -33,6 +33,11 @@ test('/ (custom assets directory)', async t => {
t.true(html.includes('.global-css-selector')) t.true(html.includes('.global-css-selector'))
}) })
test('/ (custom layouts directory)', async t => {
const { html } = await nuxt.renderRoute('/')
t.true(html.includes('<p>I have custom layouts directory</p>'))
})
test('/ (custom pages directory)', async t => { test('/ (custom pages directory)', async t => {
const { html } = await nuxt.renderRoute('/') const { html } = await nuxt.renderRoute('/')
t.true(html.includes('<h1>I have custom pages directory</h1>')) t.true(html.includes('<h1>I have custom pages directory</h1>'))

View File

@ -0,0 +1,6 @@
<template>
<div>
<nuxt/>
<p>I have custom layouts directory</p>
</div>
</template>

View File

@ -2,6 +2,7 @@ module.exports = {
css: [{ src: '~/custom-assets/app.css' }], css: [{ src: '~/custom-assets/app.css' }],
dir: { dir: {
assets: 'custom-assets', assets: 'custom-assets',
layouts: 'custom-layouts',
pages: 'custom-pages', pages: 'custom-pages',
static: 'custom-static' static: 'custom-static'
} }