docusaurus/website/docs/api/docusaurus.config.js.md
Teik Jun 300aecb8bc
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 8b2caaa091.

* 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 21:14:49 +02:00

6.9 KiB

id title description slug
docusaurus.config.js docusaurus.config.js API reference for Docusaurus configuration file. /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

Title for your website.

module.exports = {
  title: 'Docusaurus',
};

favicon

  • Type: string

URL for site favicon. Example:

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:

.
├── README.md
├ # ... other files in root directory
└─ static
    └── img
        └── favicon.ico

So you can refer it like below:

module.exports = {
  favicon: 'img/favicon.ico',
};

url

  • Type: string

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 field.

module.exports = {
  url: 'https://docusaurus.io',
};

baseUrl

  • Type: string

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 field.

module.exports = {
  baseUrl: '/',
};

Optional fields

  • 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).

:::

onDuplicateRoutes

  • Type: 'ignore' | 'log' | 'warn' | 'error' | 'throw'

The behavior of Docusaurus when it detects any duplicate routes.

By default, it displays a warning after you run yarn start or yarn build.

tagline

  • Type: string

The tagline for your website.

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.

module.exports = {
  // Docusaurus' organization is facebook
  organizationName: 'facebook',
};

projectName

  • Type: string

The name of the GitHub repository. Used by the deployment command.

module.exports = {
  projectName: 'docusaurus',
};

githubHost

  • Type: string

The hostname of your server. Useful if you are using GitHub Enterprise.

module.exports = {
  githubHost: 'github.com',
};

themeConfig

  • Type: Object

An object containing data needed by the theme you use.

For Docusaurus' default theme classic, we use themeConfig to customize your navbar and footer links:

Example:

module.exports = {
  themeConfig: {
    colorMode: {
      defaultMode: 'light',
      disableSwitch: false,
      respectPrefersColorScheme: true,
      switchConfig: {
        darkIcon: '🌙',
        darkIconStyle: { // Style object passed to inline CSS
        // For more information about styling options visit: https://reactjs.org/docs/dom-elements.html#style
          marginLeft: '2px',
        },
        lightIcon: '\u2600',
        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

  • Type: any[]
module.exports = {
  plugins: [],
};

themes

  • Type: any[]
module.exports = {
  themes: [],
};

presets

  • Type: any[]
module.exports = {
  presets: [],
};

customFields

Docusaurus guards docusaurus.config.js from unknown fields. To add a custom field, define it on customFields.

  • Type: Object
module.exports = {
  customFields: {
    admin: 'endi',
    superman: 'lol',
  },
};

Attempting to add unknown field in the config will lead to error in build time:

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:

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,
    },
  ],
};

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:

module.exports = {
  stylesheets: [
    // String format.
    'https://docusaurus.io/style.css',
    // Object format.
    {
      href: 'http://mydomain.com/style.css',
      type: 'text/css',
    },
  ],
};