mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 22:25:12 +00:00
feat: custom layouts directory
This commit is contained in:
parent
536aab6380
commit
b3f2a67793
@ -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(
|
||||||
|
@ -286,6 +286,7 @@ Options.defaults = {
|
|||||||
},
|
},
|
||||||
dir: {
|
dir: {
|
||||||
assets: 'assets',
|
assets: 'assets',
|
||||||
|
layouts: 'layouts',
|
||||||
pages: 'pages',
|
pages: 'pages',
|
||||||
static: 'static'
|
static: 'static'
|
||||||
},
|
},
|
||||||
|
@ -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>'))
|
||||||
|
6
test/fixtures/custom-dirs/custom-layouts/default.vue
vendored
Normal file
6
test/fixtures/custom-dirs/custom-layouts/default.vue
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<nuxt/>
|
||||||
|
<p>I have custom layouts directory</p>
|
||||||
|
</div>
|
||||||
|
</template>
|
1
test/fixtures/custom-dirs/nuxt.config.js
vendored
1
test/fixtures/custom-dirs/nuxt.config.js
vendored
@ -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'
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user