docusaurus/website/docs/api/docusaurus.config.js.md

419 lines
9.5 KiB
Markdown
Raw Normal View History

---
id: docusaurus.config.js
title: docusaurus.config.js
2019-10-25 12:35:02 -04:00
description: API reference for Docusaurus configuration file.
feat(v2): warn user when there are conflicting routes (#3083) * feat(v2): add warning for path override * feat(v2): check all routes recursively * docs(v2): add docs for conflicting routes * style(v2): improve comments in code * refactor(v2): remove unused lifecycle method from docs plugin * Revert "refactor(v2): remove unused lifecycle method from docs plugin" This reverts commit 8b2caaa0917f00b4706c6a135a7311db50991304. * feat(v2): add option for changing duplicate path behavior * feat(v2): decouple logging from logic and detect duplicate routes in one pass * test(v2): fix failing tests * test(v2): add tests for duplicateRoutes * test(v2): add test for handleDuplicateRoutes * style(v2): add else statement * docs(v2): modify documentation for duplicate routes * docs(v2): move doc into guides folder * fix(v2): fix broken links * docs(v2): move docs for docusaurus config into api folder * style(v2): add comments * refactor(v2): extract getFinalRoutes * refactor(v2): scope getFinalRoutes to docusaurus package * test(v2): remove obsolete snapshots * docs(v2): remove some docs * fix(v2): rerun github actions * docs(v2): change slug of docs in api folder * refactor(v2): extract out a reportMessage method * refactor(v2): extract getAllFinalRoutes * test(v2): replace snapshots with actual value * style(v2): remove unnecessary comment and change type * chore(v2): remove unused dependency * style(v2): remove unused code * Update packages/docusaurus/src/server/utils.ts * Update website/docs/guides/creating-pages.md Co-authored-by: Sébastien Lorber <slorber@users.noreply.github.com>
2020-07-31 15:14:49 -04:00
slug: /docusaurus.config.js
---
## Overview
`docusaurus.config.js` contains configurations for your site and is placed in the root directory of your site.
## Required fields
### `title`
- Type: `string`
2019-10-25 12:35:02 -04:00
Title for your website.
```js title="docusaurus.config.js"
module.exports = {
title: 'Docusaurus',
};
```
### `favicon`
- Type: `string`
2019-10-25 12:35:02 -04:00
URL for site favicon. Example:
```js title="docusaurus.config.js"
2019-10-25 12:35:02 -04:00
module.exports = {
favicon: 'https://v2.docusaurus.io/favicon.ico',
};
```
You can also use the favicon URL relative to the `static` directory of your site. For example, your site has the following directory structure:
```bash
.
├── README.md
├ # ... other files in root directory
└─ static
└── img
└── favicon.ico
```
2019-10-25 12:35:02 -04:00
So you can refer it like below:
```js title="docusaurus.config.js"
module.exports = {
favicon: 'img/favicon.ico',
};
```
### `url`
- Type: `string`
2019-10-25 12:35:02 -04:00
URL for your website. This can also be considered the top-level hostname. For example, `https://facebook.github.io` is the URL of https://facebook.github.io/metro/, and `https://docusaurus.io` is the URL for https://docusaurus.io. This field is related to the [baseUrl](#baseurl) field.
```js title="docusaurus.config.js"
module.exports = {
url: 'https://docusaurus.io',
};
```
### `baseUrl`
- Type: `string`
2019-10-25 12:35:02 -04:00
Base URL for your site. This can also be considered the path after the host. For example, `/metro/` is the baseUrl of https://facebook.github.io/metro/. For URLs that have no path, the baseUrl should be set to `/`. This field is related to the [url](#url) field.
```js title="docusaurus.config.js"
module.exports = {
baseUrl: '/',
};
```
## Optional fields
### `noIndex`
- Type: `boolean`
This option adds `<meta name="robots" content="noindex, nofollow">` in pages, to tell search engines to avoid indexing your site (more information [here](https://moz.com/learn/seo/robots-meta-directives)).
Example:
```js title="docusaurus.config.js"
module.exports = {
noIndex: true, // Defaults to `false`
};
```
### `onBrokenLinks`
feat(v2): warn user when there are conflicting routes (#3083) * feat(v2): add warning for path override * feat(v2): check all routes recursively * docs(v2): add docs for conflicting routes * style(v2): improve comments in code * refactor(v2): remove unused lifecycle method from docs plugin * Revert "refactor(v2): remove unused lifecycle method from docs plugin" This reverts commit 8b2caaa0917f00b4706c6a135a7311db50991304. * feat(v2): add option for changing duplicate path behavior * feat(v2): decouple logging from logic and detect duplicate routes in one pass * test(v2): fix failing tests * test(v2): add tests for duplicateRoutes * test(v2): add test for handleDuplicateRoutes * style(v2): add else statement * docs(v2): modify documentation for duplicate routes * docs(v2): move doc into guides folder * fix(v2): fix broken links * docs(v2): move docs for docusaurus config into api folder * style(v2): add comments * refactor(v2): extract getFinalRoutes * refactor(v2): scope getFinalRoutes to docusaurus package * test(v2): remove obsolete snapshots * docs(v2): remove some docs * fix(v2): rerun github actions * docs(v2): change slug of docs in api folder * refactor(v2): extract out a reportMessage method * refactor(v2): extract getAllFinalRoutes * test(v2): replace snapshots with actual value * style(v2): remove unnecessary comment and change type * chore(v2): remove unused dependency * style(v2): remove unused code * Update packages/docusaurus/src/server/utils.ts * Update website/docs/guides/creating-pages.md Co-authored-by: Sébastien Lorber <slorber@users.noreply.github.com>
2020-07-31 15:14:49 -04:00
- Type: `'ignore' | 'log' | 'warn' | 'error' | 'throw'`
The behavior of Docusaurus, when it detects any broken link.
By default, it throws an error, to ensure you never ship any broken link, but you can lower this security if needed.
:::note
The broken links detection is only available for a production build (`docusaurus build`).
:::
feat(v2): warn user when there are conflicting routes (#3083) * feat(v2): add warning for path override * feat(v2): check all routes recursively * docs(v2): add docs for conflicting routes * style(v2): improve comments in code * refactor(v2): remove unused lifecycle method from docs plugin * Revert "refactor(v2): remove unused lifecycle method from docs plugin" This reverts commit 8b2caaa0917f00b4706c6a135a7311db50991304. * feat(v2): add option for changing duplicate path behavior * feat(v2): decouple logging from logic and detect duplicate routes in one pass * test(v2): fix failing tests * test(v2): add tests for duplicateRoutes * test(v2): add test for handleDuplicateRoutes * style(v2): add else statement * docs(v2): modify documentation for duplicate routes * docs(v2): move doc into guides folder * fix(v2): fix broken links * docs(v2): move docs for docusaurus config into api folder * style(v2): add comments * refactor(v2): extract getFinalRoutes * refactor(v2): scope getFinalRoutes to docusaurus package * test(v2): remove obsolete snapshots * docs(v2): remove some docs * fix(v2): rerun github actions * docs(v2): change slug of docs in api folder * refactor(v2): extract out a reportMessage method * refactor(v2): extract getAllFinalRoutes * test(v2): replace snapshots with actual value * style(v2): remove unnecessary comment and change type * chore(v2): remove unused dependency * style(v2): remove unused code * Update packages/docusaurus/src/server/utils.ts * Update website/docs/guides/creating-pages.md Co-authored-by: Sébastien Lorber <slorber@users.noreply.github.com>
2020-07-31 15:14:49 -04:00
### `onDuplicateRoutes`
- Type: `'ignore' | 'log' | 'warn' | 'error' | 'throw'`
The behavior of Docusaurus when it detects any [duplicate routes](/guides/creating-pages.md#duplicate-routes).
By default, it displays a warning after you run `yarn start` or `yarn build`.
### `tagline`
- Type: `string`
The tagline for your website.
```js title="docusaurus.config.js"
module.exports = {
tagline:
'Docusaurus makes it easy to maintain Open Source documentation websites.',
};
```
### `organizationName`
- Type: `string`
The GitHub user or organization that owns the repository. Used by the deployment command.
```js title="docusaurus.config.js"
module.exports = {
// Docusaurus' organization is facebook
organizationName: 'facebook',
};
```
### `projectName`
- Type: `string`
The name of the GitHub repository. Used by the deployment command.
```js title="docusaurus.config.js"
module.exports = {
projectName: 'docusaurus',
};
```
### `githubHost`
- Type: `string`
The hostname of your server. Useful if you are using GitHub Enterprise.
```js title="docusaurus.config.js"
module.exports = {
githubHost: 'github.com',
};
```
### `themeConfig`
- Type: `Object`
<!-- TODO: explain that theme configurations will be consumed by the theme, and link to theme doc -->
An object containing data needed by the theme you use.<!--, see [theme configurations](#).-->
For Docusaurus' default theme _classic_, we use `themeConfig` to customize your navbar and footer links:
2019-10-25 12:35:02 -04:00
Example:
```js title="docusaurus.config.js"
module.exports = {
themeConfig: {
colorMode: {
defaultMode: 'light',
disableSwitch: false,
respectPrefersColorScheme: true,
switchConfig: {
darkIcon: '🌙',
lightIcon: '\u2600',
// React inline style object
// see https://reactjs.org/docs/dom-elements.html#style
darkIconStyle: {
marginLeft: '2px',
},
lightIconStyle: {
marginLeft: '1px',
},
},
},
navbar: {
title: 'Site Title',
logo: {
alt: 'Site Logo',
src: 'img/logo.svg',
},
items: [
{
to: 'docs/docusaurus.config.js',
activeBasePath: 'docs',
label: 'docusaurus.config.js',
position: 'left',
},
// ... other links
],
},
footer: {
style: 'dark',
links: [
{
title: 'Docs',
items: [
{
label: 'Docs',
to: 'docs/doc1',
},
],
},
// ... other links
],
logo: {
alt: 'Facebook Open Source Logo',
src: 'https://docusaurus.io/img/oss_logo.png',
},
copyright: `Copyright © ${new Date().getFullYear()} Facebook, Inc.`, // You can also put own HTML here
},
},
};
```
### `plugins`
<!-- TODO: configuration for plugins -->
- Type: `any[]`
```js title="docusaurus.config.js"
module.exports = {
plugins: [],
};
```
### `themes`
<!-- TODO: configuration for plugins -->
- Type: `any[]`
```js title="docusaurus.config.js"
module.exports = {
themes: [],
};
```
### `presets`
<!-- TODO: configuration for presets -->
- Type: `any[]`
```js title="docusaurus.config.js"
module.exports = {
presets: [],
};
```
2019-06-03 08:55:45 -04:00
### `customFields`
2020-05-17 23:37:53 -04:00
Docusaurus guards `docusaurus.config.js` from unknown fields. To add a custom field, define it on `customFields`.
2019-06-03 08:55:45 -04:00
- Type: `Object`
```js title="docusaurus.config.js"
module.exports = {
2019-06-03 08:55:45 -04:00
customFields: {
admin: 'endi',
superman: 'lol',
2019-06-03 08:55:45 -04:00
},
};
```
2019-06-03 08:55:45 -04:00
Attempting to add unknown field in the config will lead to error in build time:
```bash
Error: The field(s) 'foo', 'bar' are not recognized in docusaurus.config.js
```
### `scripts`
An array of scripts to load. The values can be either strings or plain objects of attribute-value maps. The `<script>` tags will be inserted in the HTML `<head>`.
Note that `<script>` added here are render-blocking so you might want to add `async: true`/`defer: true` to the objects.
- Type: `(string | Object)[]`
Example:
```js title="docusaurus.config.js"
module.exports = {
scripts: [
// String format.
'https://docusaurus.io/script.js',
// Object format.
{
src:
'https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.0/clipboard.min.js',
async: true,
},
],
};
```
### `clientModules`
An array of client modules to load globally on your site:
Example:
```js title="docusaurus.config.js"
module.exports = {
clientModules: [
require.resolve('./mySiteGlobalJs.js'),
require.resolve('./mySiteGlobalCss.css'),
],
};
```
See also: [`getClientModules()`](lifecycle-apis.md#getclientmodules).
### `ssrTemplate`
An HTML template written in [Eta's syntax](https://eta.js.org/docs/syntax#syntax-overview) that will be used to render your application. This can be used to set custom attributes on the `body` tags, additional `meta` tags, customize the `viewport`, etc. Please note that Docusaurus will rely on the template to be correctly structured in order to function properly, once you do customize it, you will have to make sure that your template is compliant with the requirements from `upstream`.
- Type: `string`
Example:
```js title="docusaurus.config.js"
module.exports = {
ssrTemplate: `<!DOCTYPE html>
<html <%~ it.htmlAttributes %>>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=0.86, maximum-scale=3.0, minimum-scale=0.86">
<meta name="generator" content="Docusaurus v<%= it.version %>">
<%~ it.headTags %>
<% it.metaAttributes.forEach((metaAttribute) => { %>
<%~ metaAttribute %>
<% }); %>
<% it.stylesheets.forEach((stylesheet) => { %>
<link rel="stylesheet" type="text/css" href="<%= it.baseUrl %><%= stylesheet %>" />
<% }); %>
<% it.scripts.forEach((script) => { %>
<link rel="preload" href="<%= it.baseUrl %><%= script %>" as="script">
<% }); %>
</head>
<body <%~ it.bodyAttributes %> itemscope="" itemtype="http://schema.org/Organization">
<%~ it.preBodyTags %>
<div id="__docusaurus">
<%~ it.appHtml %>
</div>
<div id="outside-docusaurus">
<span>Custom markup</span>
</div>
<% it.scripts.forEach((script) => { %>
<script type="text/javascript" src="<%= it.baseUrl %><%= script %>"></script>
<% }); %>
<%~ it.postBodyTags %>
</body>
</html>
};
```
### `stylesheets`
An array of CSS sources to load. The values can be either strings or plain objects of attribute-value maps. The `<link>` tags will be inserted in the HTML `<head>`.
- Type: `(string | Object)[]`
Example:
```js title="docusaurus.config.js"
module.exports = {
stylesheets: [
// String format.
'https://docusaurus.io/style.css',
// Object format.
{
href: 'http://mydomain.com/style.css',
type: 'text/css',
},
],
};
```
### `titleDelimiter`
- Type: `string`
A string that will be used as title delimiter in the generated `<title>` tag.
Example:
```js title="docusaurus.config.js"
module.exports = {
titleDelimiter: '🦖', // Defaults to `|`
};
```