提交 8024453d 编写于 作者: E Evan You

improve theme resolution

上级 1131c681
......@@ -111,19 +111,26 @@ async function resolveOptions (sourceDir) {
options.themePath = path.resolve(__dirname, 'default-theme/Layout.vue')
options.notFoundPath = path.resolve(__dirname, 'default-theme/NotFound.vue')
} else {
let themeDir
let themePath
// resolve custom theme
const themeDir = siteConfig.theme
? path.resolve(__dirname, `../../vuepress-theme-${siteConfig.theme}`)
: path.resolve(vuepressDir, 'theme')
const themePath = path.resolve(themeDir, 'Layout.vue')
if (fs.existsSync(themePath)) {
options.themePath = themePath
if (siteConfig.theme) {
try {
themePath = require.resolve(`vuepress-theme-${siteConfig.theme}/Layout.vue`)
themeDir = path.dirname(themePath)
} catch (e) {
throw new Error(`[vuepress] Failed to load custom theme "${
siteConfig.theme
}". File vuepress-theme-${siteConfig.theme}/Layout.vue does not exist.`)
}
} else {
throw new Error(`[vuepress] Cannot resolve Layout.vue file for custom theme${
siteConfig.theme ? ` "${siteConfig.theme}"` : ``
}.`)
themeDir = path.resolve(vuepressDir, 'theme')
themePath = path.resolve(themeDir, 'Layout.vue')
if (!fs.existsSync(themePath)) {
throw new Error(`[vuepress] Cannot resolve Layout.vue file in .vuepress/theme.`)
}
}
options.themePath = themePath
const notFoundPath = path.resolve(themeDir, '/NotFound.vue')
if (fs.existsSync(notFoundPath)) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册