From af80c4b61af0f0ce4e380b050c922fca7916d13e Mon Sep 17 00:00:00 2001 From: ULIVZ <472590061@qq.com> Date: Sat, 27 Oct 2018 20:46:24 +0800 Subject: [PATCH] fix($core): globally installed vuepress doesn't work (close: #908, #949) --- .../core/lib/webpack/createBaseConfig.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/@vuepress/core/lib/webpack/createBaseConfig.js b/packages/@vuepress/core/lib/webpack/createBaseConfig.js index e32adcb2b6..4ee60bf365 100644 --- a/packages/@vuepress/core/lib/webpack/createBaseConfig.js +++ b/packages/@vuepress/core/lib/webpack/createBaseConfig.js @@ -46,6 +46,9 @@ module.exports = function createBaseConfig ({ config.devtool('cheap-module-eval-source-map') } + const modulePaths = getModulePaths() + logger.debug('modulePaths = ' + JSON.stringify(modulePaths, null, 2)) + config.resolve .set('symlinks', true) .alias @@ -60,18 +63,12 @@ module.exports = function createBaseConfig ({ .merge(['.js', '.jsx', '.vue', '.json', '.styl']) .end() .modules - // prioritize our own - .add(path.resolve(__dirname, '../../node_modules')) - .add(path.resolve(__dirname, '../../../')) - .add('node_modules') + .merge(modulePaths) config.resolveLoader .set('symlinks', true) .modules - // prioritize our own - .add(path.resolve(__dirname, '../../node_modules')) - .add(path.resolve(__dirname, '../../../')) - .add('node_modules') + .merge(modulePaths) config.module .noParse(/^(vue|vue-router|vuex|vuex-router-sync)$/) @@ -320,3 +317,7 @@ function getLastCommitHash () { } catch (error) {} return hash } + +function getModulePaths () { + return [path.resolve(process.cwd(), 'node_modules')].concat(module.paths) +}