From 19420efbc74f1bf00e6b3514da7e69c75f83b40e Mon Sep 17 00:00:00 2001 From: neumayr Date: Fri, 1 Mar 2019 16:09:26 +0100 Subject: [PATCH] allow merging of yaml, toml, js config MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * allows the merging `yaml`, `toml`, `js` config * update documentation section My Team manages eg. `themeConfig.nav` in `config.yml` for readability and ease of use. However some advanced js syntax can’t be managed by `yaml` like `extendMarkdown: md => {md.use(…)}`. I would like to have two configuration files. `config.yml` and `config.js` work side by side. One for simple theme config and the js for advanced configuration. :link: https://github.com/vuejs/vuepress/pull/804 --- .../prepare/fixtures/docs-config/.vuepress/config.js | 2 -- .../fixtures/docs-config/.vuepress/config.yml | 3 +++ packages/@vuepress/core/lib/prepare/loadConfig.js | 12 +++++++----- packages/docs/docs/.vuepress/config.js | 6 +++--- packages/docs/docs/guide/basic-config.md | 2 +- 5 files changed, 14 insertions(+), 11 deletions(-) create mode 100644 packages/@vuepress/core/__tests__/prepare/fixtures/docs-config/.vuepress/config.yml diff --git a/packages/@vuepress/core/__tests__/prepare/fixtures/docs-config/.vuepress/config.js b/packages/@vuepress/core/__tests__/prepare/fixtures/docs-config/.vuepress/config.js index 665e1164b3..f4019472e5 100644 --- a/packages/@vuepress/core/__tests__/prepare/fixtures/docs-config/.vuepress/config.js +++ b/packages/@vuepress/core/__tests__/prepare/fixtures/docs-config/.vuepress/config.js @@ -1,6 +1,4 @@ module.exports = { - title: 'Hello VuePress', - description: '# Hello, VuePress!', dest: 'vuepress', base: 'vuepress', head: [ diff --git a/packages/@vuepress/core/__tests__/prepare/fixtures/docs-config/.vuepress/config.yml b/packages/@vuepress/core/__tests__/prepare/fixtures/docs-config/.vuepress/config.yml new file mode 100644 index 0000000000..d84b90de9e --- /dev/null +++ b/packages/@vuepress/core/__tests__/prepare/fixtures/docs-config/.vuepress/config.yml @@ -0,0 +1,3 @@ +--- +title: Hello VuePress +description: '# Hello, VuePress!' diff --git a/packages/@vuepress/core/lib/prepare/loadConfig.js b/packages/@vuepress/core/lib/prepare/loadConfig.js index c786e88d44..ad4cd45f79 100644 --- a/packages/@vuepress/core/lib/prepare/loadConfig.js +++ b/packages/@vuepress/core/lib/prepare/loadConfig.js @@ -24,11 +24,13 @@ module.exports = function loadConfig (vuepressDir, bustCache = true) { // resolve siteConfig let siteConfig = {} if (fs.existsSync(configYmlPath)) { - siteConfig = parseConfig(configYmlPath) - } else if (fs.existsSync(configTomlPath)) { - siteConfig = parseConfig(configTomlPath) - } else if (fs.existsSync(configPath)) { - siteConfig = require(configPath) + siteConfig = Object.assign(siteConfig, parseConfig(configYmlPath)) + } + if (fs.existsSync(configTomlPath)) { + siteConfig = Object.assign(siteConfig, parseConfig(configTomlPath)) + } + if (fs.existsSync(configPath)) { + siteConfig = Object.assign(siteConfig, require(configPath)) } return siteConfig diff --git a/packages/docs/docs/.vuepress/config.js b/packages/docs/docs/.vuepress/config.js index b56d1334ed..a3d5d281ec 100755 --- a/packages/docs/docs/.vuepress/config.js +++ b/packages/docs/docs/.vuepress/config.js @@ -1,6 +1,6 @@ const container = require('markdown-it-container') -module.exports = ctx => ({ +module.exports = { dest: '../../vuepress', locales: { '/': { @@ -63,7 +63,7 @@ module.exports = ctx => ({ } }, plugins: [ - ['@vuepress/i18n-ui', !ctx.isProd], + ['@vuepress/i18n-ui'], ['@vuepress/back-to-top', true], ['@vuepress/pwa', { serviceWorker: true, @@ -82,7 +82,7 @@ module.exports = ctx => ({ : '' }) }, -}) +} function getGuideSidebar (groupA, groupB) { return [ diff --git a/packages/docs/docs/guide/basic-config.md b/packages/docs/docs/guide/basic-config.md index 5a17dbcd01..7ba7cfb13e 100644 --- a/packages/docs/docs/guide/basic-config.md +++ b/packages/docs/docs/guide/basic-config.md @@ -27,7 +27,7 @@ If you've got the dev server running, you should see the page now has a header w Consult the [Config Reference](../config/README.md) for a full list of options. ::: tip Alternative Config Formats -You can also use YAML (`.vuepress/config.yml`) or TOML (`.vuepress/config.toml`) formats for the configuration file. +You can also split config and use YAML (`.vuepress/config.yml`) or TOML (`.vuepress/config.toml`) formats for the configuration. All configuration files will be merged together. ::: ## Theme Configuration