You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: website/docs/api/docusaurus.config.js.mdx
+13-20Lines changed: 13 additions & 20 deletions
Original file line number
Diff line number
Diff line change
@@ -16,40 +16,33 @@ Refer to the Getting Started [**Configuration**](docs/configuration.mdx) for exa
16
16
17
17
`docusaurus.config.js` contains configurations for your site and is placed in the root directory of your site.
18
18
19
-
It usually exports a site configuration object:
19
+
This file is run in Node.js using the [**CommonJS**](https://flaviocopes.com/commonjs/) module system, and should export a site configuration object, or a function that creates it.
20
+
21
+
Examples:
20
22
21
23
```js title="docusaurus.config.js"
22
24
module.exports= {
23
-
// site config...
25
+
title:'Docusaurus',
26
+
url:'https://docusaurus.io',
27
+
// your site config ...
24
28
};
25
29
```
26
30
27
-
<details>
28
-
<summary>Config files also support config creator functions and async code.</summary>
Refer to [**Syntax to declare `docusaurus.config.js`**](docs/configuration.mdx#syntax-to-declare-docusaurus-config) for a more exhaustive list of examples and explanations.
Copy file name to clipboardExpand all lines: website/docs/configuration.mdx
+77Lines changed: 77 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -16,6 +16,83 @@ Docusaurus has a unique take on configurations. We encourage you to congregate i
16
16
17
17
Keeping a well-maintained `docusaurus.config.js` helps you, your collaborators, and your open source contributors to be able to focus on documentation while still being able to customize the site.
18
18
19
+
## Syntax to declare `docusaurus.config.js`{#syntax-to-declare-docusaurus-config}
20
+
21
+
The `docusaurus.config.js` file is run in Node.js and should export either:
22
+
23
+
- a **config object**
24
+
- a **function** that creates the config object
25
+
26
+
:::info
27
+
28
+
The `docusaurus.config.js` file only supports the [**CommonJS**](https://flaviocopes.com/commonjs/) module system:
29
+
30
+
-**Required:** use `module.exports = /* your config*/` to export your Docusaurus config
31
+
-**Optional:** use `require("lib")` to import Node.js packages
32
+
-**Optional:** use `await import("lib")` (dynamic import) in an async function to import ESM-Only Node.js packages
33
+
34
+
:::
35
+
36
+
Node.js gives us the ability to declare our Docusaurus configuration in various **equivalent ways**, and all the following config examples lead to the exact same result:
37
+
38
+
```js title="docusaurus.config.js"
39
+
module.exports= {
40
+
title:'Docusaurus',
41
+
url:'https://docusaurus.io',
42
+
// your site config ...
43
+
};
44
+
```
45
+
46
+
```js title="docusaurus.config.js"
47
+
constconfig= {
48
+
title:'Docusaurus',
49
+
url:'https://docusaurus.io',
50
+
// your site config ...
51
+
};
52
+
53
+
module.exports= config;
54
+
```
55
+
56
+
```js title="docusaurus.config.js"
57
+
module.exports=functionconfigCreator() {
58
+
return {
59
+
title:'Docusaurus',
60
+
url:'https://docusaurus.io',
61
+
// your site config ...
62
+
};
63
+
};
64
+
```
65
+
66
+
```js title="docusaurus.config.js"
67
+
module.exports=asyncfunctioncreateConfigAsync() {
68
+
return {
69
+
title:'Docusaurus',
70
+
url:'https://docusaurus.io',
71
+
// your site config ...
72
+
};
73
+
};
74
+
```
75
+
76
+
:::tip Using ESM-only packages
77
+
78
+
Using an async config creator can be useful to import ESM-only modules (notably most Remark plugins). It is possible to import such modules thanks to dynamic imports:
79
+
80
+
```js title="docusaurus.config.js"
81
+
module.exports=asyncfunctioncreateConfigAsync() {
82
+
// Use a dynamic import instead of require('esm-lib')
83
+
// highlight-next-line
84
+
constlib=awaitimport('lib');
85
+
86
+
return {
87
+
title:'Docusaurus',
88
+
url:'https://docusaurus.io',
89
+
// rest of your site config...
90
+
};
91
+
};
92
+
```
93
+
94
+
:::
95
+
19
96
## What goes into a `docusaurus.config.js`? {#what-goes-into-a-docusaurusconfigjs}
20
97
21
98
You should not have to write your `docusaurus.config.js` from scratch even if you are developing your site. All templates come with a `docusaurus.config.js` that includes defaults for the common options.
0 commit comments