diff --git a/lib/core/module.js b/lib/core/module.js index 7dc6d904bd..c60aa70f31 100755 --- a/lib/core/module.js +++ b/lib/core/module.js @@ -71,6 +71,14 @@ module.exports = class ModuleContainer { }) } + addLayout(template, name) { + const { dst, src } = this.addTemplate(template) + const srcPath = path.parse(src) + + // Add to nuxt layouys + this.options.layouts[name || srcPath.name] = `./${dst}` + } + addServerMiddleware(middleware) { this.options.serverMiddleware.push(middleware) } diff --git a/test/fixtures/module/modules/basic/index.js b/test/fixtures/module/modules/basic/index.js index aab03927b0..99428e1093 100755 --- a/test/fixtures/module/modules/basic/index.js +++ b/test/fixtures/module/modules/basic/index.js @@ -8,6 +8,9 @@ module.exports = function basicModule(options, resolve) { // Add a plugin this.addPlugin(path.resolve(__dirname, 'reverse.js')) + // Add a layout + this.addLayout(path.resolve(__dirname, 'layout.vue')) + // Extend build this.extendBuild((config, { isClient, isServer }) => { // Do nothing! diff --git a/test/fixtures/module/modules/basic/layout.vue b/test/fixtures/module/modules/basic/layout.vue new file mode 100644 index 0000000000..ed699cfa2f --- /dev/null +++ b/test/fixtures/module/modules/basic/layout.vue @@ -0,0 +1,6 @@ + diff --git a/test/fixtures/module/router.js b/test/fixtures/module/router.js index 3899de8cd8..ac5f850f8b 100644 --- a/test/fixtures/module/router.js +++ b/test/fixtures/module/router.js @@ -5,6 +5,7 @@ Vue.use(Router) const indexPage = () => import('~/views/index.vue').then(m => m.default || m) const aboutPage = () => import('~/views/about.vue').then(m => m.default || m) +const layoutPage = () => import('~/views/layout.vue').then(m => m.default || m) export function createRouter() { return new Router({ @@ -19,6 +20,11 @@ export function createRouter() { path: '/about', component: aboutPage, name: 'about' + }, + { + path: '/layout', + component: layoutPage, + name: 'layout' } ] }) diff --git a/test/fixtures/module/views/layout.vue b/test/fixtures/module/views/layout.vue new file mode 100644 index 0000000000..9bf372487d --- /dev/null +++ b/test/fixtures/module/views/layout.vue @@ -0,0 +1,10 @@ + + diff --git a/test/module.test.js b/test/module.test.js index 61f221a304..81addd5e24 100755 --- a/test/module.test.js +++ b/test/module.test.js @@ -47,6 +47,16 @@ test.serial('Plugin', async t => { t.true(html.includes('

TXUN

'), 'plugin works') }) +test.serial('Layout', async t => { + t.true( + nuxt.options.layouts.layout.includes('layout'), + 'layout added to config' + ) + + const { html } = await nuxt.renderRoute('/layout') + t.true(html.includes('

Module Layouts

'), 'layout works') +}) + test.serial('Hooks', async t => { t.is(nuxt.__module_hook, 1) t.is(nuxt.__renderer_hook, 2)