From b3f2a67793dda6742ca42a25391d40595d18488d Mon Sep 17 00:00:00 2001 From: Ricardo Gobbo de Souza Date: Sat, 3 Feb 2018 16:41:43 -0200 Subject: [PATCH] feat: custom layouts directory --- lib/builder/builder.js | 12 ++++++------ lib/common/options.js | 1 + test/custom-dirs.test.js | 5 +++++ test/fixtures/custom-dirs/custom-layouts/default.vue | 6 ++++++ test/fixtures/custom-dirs/nuxt.config.js | 1 + 5 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 test/fixtures/custom-dirs/custom-layouts/default.vue 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 pages directory

')) diff --git a/test/fixtures/custom-dirs/custom-layouts/default.vue b/test/fixtures/custom-dirs/custom-layouts/default.vue new file mode 100644 index 0000000000..69c0ce40bf --- /dev/null +++ b/test/fixtures/custom-dirs/custom-layouts/default.vue @@ -0,0 +1,6 @@ + diff --git a/test/fixtures/custom-dirs/nuxt.config.js b/test/fixtures/custom-dirs/nuxt.config.js index d3b73492fd..6701e30b30 100644 --- a/test/fixtures/custom-dirs/nuxt.config.js +++ b/test/fixtures/custom-dirs/nuxt.config.js @@ -2,6 +2,7 @@ module.exports = { css: [{ src: '~/custom-assets/app.css' }], dir: { assets: 'custom-assets', + layouts: 'custom-layouts', pages: 'custom-pages', static: 'custom-static' }