diff --git a/lib/builder/builder.js b/lib/builder/builder.js index f537d64b23..6f9943c7a1 100644 --- a/lib/builder/builder.js +++ b/lib/builder/builder.js @@ -271,8 +271,8 @@ module.exports = class Builder { } // -- Layouts -- - if (existsSync(resolve(this.options.srcDir, 'layouts'))) { - const layoutsFiles = await glob('layouts/**/*.{vue,js}', { + if (existsSync(resolve(this.options.srcDir, this.options.dir.layouts))) { + const layoutsFiles = await glob(`${this.options.dir.layouts}/**/*.{vue,js}`, { cwd: this.options.srcDir, ignore: this.options.ignore }) @@ -297,7 +297,7 @@ module.exports = class Builder { if (!templateVars.components.ErrorPage && hasErrorLayout) { templateVars.components.ErrorPage = this.relativeToBuild( this.options.srcDir, - 'layouts/error.vue' + `${this.options.dir.layouts}/error.vue` ) } } @@ -639,11 +639,11 @@ module.exports = class Builder { watchFiles() { const src = this.options.srcDir let patterns = [ - r(src, 'layouts'), + r(src, this.options.dir.layouts), r(src, 'store'), r(src, 'middleware'), - r(src, 'layouts/*.{vue,js}'), - r(src, 'layouts/**/*.{vue,js}') + r(src, `${this.options.dir.layouts}/*.{vue,js}`), + r(src, `${this.options.dir.layouts}/**/*.{vue,js}`) ] if (this._nuxtPages) { patterns.push( diff --git a/lib/common/options.js b/lib/common/options.js index e0d0f282a3..69db1dd6ff 100755 --- a/lib/common/options.js +++ b/lib/common/options.js @@ -286,6 +286,7 @@ Options.defaults = { }, dir: { assets: 'assets', + layouts: 'layouts', pages: 'pages', static: 'static' }, diff --git a/test/custom-dirs.test.js b/test/custom-dirs.test.js index 06bddab108..c516101480 100644 --- a/test/custom-dirs.test.js +++ b/test/custom-dirs.test.js @@ -33,6 +33,11 @@ test('/ (custom assets directory)', async t => { t.true(html.includes('.global-css-selector')) }) +test('/ (custom layouts directory)', async t => { + const { html } = await nuxt.renderRoute('/') + t.true(html.includes('
I have custom layouts directory
')) +}) + test('/ (custom pages directory)', async t => { const { html } = await nuxt.renderRoute('/') t.true(html.includes('I have custom layouts directory
+