Skip to content

Commit

Permalink
fix($core): support theme index file which is not at root (close: #1362
Browse files Browse the repository at this point in the history
…) (#1376)
  • Loading branch information
shigma authored and ulivz committed Mar 2, 2019
1 parent b53324d commit 204cbe4
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions packages/@vuepress/core/lib/prepare/loadTheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,17 @@ module.exports = function loadTheme (ctx) {
function normalizeThemePath (resolved) {
const { entry, name, fromDep } = resolved
if (fromDep) {
const pkgPath = require.resolve(name)
let packageRootDir = parse(pkgPath).dir
// For those cases that "main" field was set to non-index file
// e.g. `layouts/Layout.vue`
while (!fs.existsSync(`${packageRootDir}/package.json`)) {
packageRootDir = resolve(packageRootDir, '..')
const packageRoot = require.resolve(`${name}/package.json`)
const { main } = require(packageRoot)
if (main.endsWith('.vue')) {
// For those cases that "main" field is set to an non-index file
// e.g. `layouts/Layout.vue`
return packageRoot
} else {
// For those cases that "index.js" is not at package root
// e.g. `lib/index.js` (#1362)
return parse(require.resolve(name)).dir
}
return packageRootDir
} else if (entry.endsWith('.js') || entry.endsWith('.vue')) {
return parse(entry).dir
} else {
Expand Down

0 comments on commit 204cbe4

Please sign in to comment.