diff --git a/lib/prepare.js b/lib/prepare.js index 2d0fc56db2..a12273b34c 100644 --- a/lib/prepare.js +++ b/lib/prepare.js @@ -74,9 +74,33 @@ if (!Object.assign) Object.assign = require('object-assign')` fs.existsSync(options.themeEnhanceAppPath) ) + // 7. handle plugins + const pluginFiles = [ + path.resolve(options.themeDir), + path.resolve(sourceDir, '.vuepress') + ] + + for (const pluginFile of pluginFiles) { + await loadPlugin(pluginFile, options) + } + return options } +async function loadPlugin (pluginPath, options) { + let plugin + + try { + plugin = require(pluginPath) + } catch (e) { + return + } + + if (plugin) { + await plugin({ options }) + } +} + async function resolveOptions (sourceDir) { const vuepressDir = path.resolve(sourceDir, '.vuepress') const configPath = path.resolve(vuepressDir, 'config.js') @@ -143,6 +167,7 @@ async function resolveOptions (sourceDir) { if (useDefaultTheme) { // use default theme + options.themeDir = path.resolve(__dirname, 'default-theme') options.themePath = path.resolve(__dirname, 'default-theme/Layout.vue') options.notFoundPath = path.resolve(__dirname, 'default-theme/NotFound.vue') } else {