Update builder.js

This commit is contained in:
Sébastien Chopin 2017-08-14 14:15:00 +02:00 committed by GitHub
parent 814590c15a
commit 3e41a6750b

View File

@ -162,17 +162,17 @@ export default class Builder extends Tapable {
// -- Layouts --
if (fs.existsSync(resolve(this.options.srcDir, 'layouts'))) {
const layoutsFiles = await glob('layouts/*.{vue,js}', { cwd: this.options.srcDir })
let hasErrorLayout = false
layoutsFiles.forEach((file) => {
let name = file.split('/').slice(-1)[0].replace('.vue', '').replace('.js', '')
if (name === 'error') return
let name = file.split('/').slice(-1)[0].replace(/\.(js|vue)$/, '')
if (name === 'error') {
hasErrorLayout = true
return
}
templateVars.layouts[name] = this.relativeToBuild(this.options.srcDir, file)
})
if (!templateVars.components.ErrorPage) {
if (layoutsFiles.includes('layouts/error.vue')) {
templateVars.components.ErrorPage = this.relativeToBuild(this.options.srcDir, 'layouts/error.vue')
} else if (layoutsFiles.includes('layouts/error.js')) {
templateVars.components.ErrorPage = this.relativeToBuild(this.options.srcDir, 'layouts/error.js')
}
if (!templateVars.components.ErrorPage && hasErrorLayout) {
templateVars.components.ErrorPage = this.relativeToBuild(this.options.srcDir, 'layouts/error')
}
}
// If no default layout, create its folder and add the default folder