feat(config): allow config.yml file load to be skipped (#2053)

This commit is contained in:
Tony Alves 2019-02-03 14:48:40 -08:00 committed by Shawn Erquhart
parent 22e047e723
commit 14f94a022c
2 changed files with 33 additions and 1 deletions

View File

@ -111,7 +111,10 @@ export function loadConfig() {
try {
const preloadedConfig = getState().config;
const configUrl = getConfigUrl();
const loadedConfig = await getConfig(configUrl, preloadedConfig && preloadedConfig.size > 1);
const loadedConfig =
preloadedConfig && preloadedConfig.get('load_config_file') === false
? {}
: await getConfig(configUrl, preloadedConfig && preloadedConfig.size > 1);
/**
* Merge any existing configuration so the result can be validated.

View File

@ -134,6 +134,35 @@ init({
},
})
/**
* Optionally pass in a complete config object and set a flag
* (`load_config_file: false`) to ignore the `config.yml`.
*
* For example, the code below contains a complete config. The
* `config.yml` will be ignored when setting `load_config_file` to false.
* It is not required if the `config.yml` file is missing to set
* `load_config_file`, but will improve performance and avoid a load error.
*/
init({
config: {
backend: {
name: 'git-gateway',
},
load_config_file: false,
media_folder: "static/images/uploads",
public_folder: "/images/uploads",
collections: [
{ label: "Blog", name: "blog", folder: "_posts/blog", create: true, fields: [
{ label: "Title", name: "title", widget: "string" },
{ label: "Publish Date", name: "date", widget: "datetime" },
{ label: "Featured Image", name: "thumbnail", widget: "image" },
{ label: "Body", name: "body", widget: "markdown" },
]},
],
},
})
// The registry works as expected, and can be used before or after init.
CMS.registerPreviewTemplate(...);
```