diff --git a/packages/builder/src/builder.js b/packages/builder/src/builder.js index 726f50d6bc..4703749e32 100644 --- a/packages/builder/src/builder.js +++ b/packages/builder/src/builder.js @@ -349,7 +349,8 @@ export default class Builder { } return } - if (!templateVars.layouts[name] && /\.vue$/.test(file)) { + // .vue file takes precedence over other extensions + if (!templateVars.layouts[name] || /\.vue$/.test(file)) { templateVars.layouts[name] = this.relativeToBuild( this.options.srcDir, file @@ -382,6 +383,7 @@ export default class Builder { ignore: this.options.ignore })).forEach((f) => { const key = f.replace(new RegExp(`\\.(${this.supportedExtensions.join('|')})$`), '') + // .vue file takes precedence over other extensions if (/\.vue$/.test(f) || !files[key]) { files[key] = f.replace(/(['"])/g, '\\$1') } diff --git a/test/fixtures/basic/layouts/custom.js b/test/fixtures/basic/layouts/custom.js new file mode 100644 index 0000000000..b0bcd797b8 --- /dev/null +++ b/test/fixtures/basic/layouts/custom.js @@ -0,0 +1,10 @@ +export default { + render(h) { + return h('div', + [ + h('h1', 'JS Layout'), + h('nuxt') + ] + ) + } +} diff --git a/test/fixtures/basic/layouts/default.vue b/test/fixtures/basic/layouts/default.vue new file mode 100644 index 0000000000..0acb4c7997 --- /dev/null +++ b/test/fixtures/basic/layouts/default.vue @@ -0,0 +1,5 @@ + diff --git a/test/fixtures/basic/pages/custom.js b/test/fixtures/basic/pages/custom.js new file mode 100644 index 0000000000..98982336b2 --- /dev/null +++ b/test/fixtures/basic/pages/custom.js @@ -0,0 +1,6 @@ +export default { + layout: 'custom', + render(h) { + return h('h2', 'custom page') + } +} diff --git a/test/fixtures/spa/layouts/custom.vue b/test/fixtures/spa/layouts/custom.vue index 675f81c88a..da28a42595 100644 --- a/test/fixtures/spa/layouts/custom.vue +++ b/test/fixtures/spa/layouts/custom.vue @@ -1,7 +1,7 @@ diff --git a/test/fixtures/spa/layouts/default.vue b/test/fixtures/spa/layouts/default.vue index 54a18850dc..0ac566cd1c 100644 --- a/test/fixtures/spa/layouts/default.vue +++ b/test/fixtures/spa/layouts/default.vue @@ -1,7 +1,7 @@ diff --git a/test/unit/basic.ssr.test.js b/test/unit/basic.ssr.test.js index 848fc14b5b..9ca12be26c 100644 --- a/test/unit/basic.ssr.test.js +++ b/test/unit/basic.ssr.test.js @@ -331,6 +331,13 @@ describe('basic ssr', () => { expect(html).toMatch('Hello unicode') }) + test('/custom (js layout)', async () => { + const window = await nuxt.server.renderAndGetWindow(url('/custom')) + const html = window.document.body.innerHTML + expect(html).toMatch('

JS Layout

') + expect(html).toMatch('

custom page

') + }) + // Close server and ask nuxt to stop listening to file changes afterAll(async () => { await nuxt.close()