diff --git a/docs/guide/configuration.md b/docs/guide/configuration.md index 7dc8d1e0..046d7dee 100644 --- a/docs/guide/configuration.md +++ b/docs/guide/configuration.md @@ -20,4 +20,9 @@ module.exports = { } ``` +::: warning +If your project uses [ES modules](https://nodejs.org/api/esm.html), +name this file `.vitepress/config.cjs` instead. +::: + Check out the [Config Reference](/config/basics) for a full list of options. diff --git a/src/node/config.ts b/src/node/config.ts index ec2ff48a..7178aba4 100644 --- a/src/node/config.ts +++ b/src/node/config.ts @@ -111,20 +111,19 @@ export async function resolveConfig( return config } -export async function resolveUserConfig(root: string) { - // load user config - const configPath = resolve(root, 'config.js') - const hasUserConfig = await fs.pathExists(configPath) - // always delete cache first before loading config - delete require.cache[configPath] - const userConfig: UserConfig = hasUserConfig ? require(configPath) : {} - if (hasUserConfig) { - debug(`loaded config at ${chalk.yellow(configPath)}`) - } else { - debug(`no config file found.`) +export async function resolveUserConfig(root: string): Promise { + for (const name of ['config.cjs', 'config.js']) { + // load user config + const configPath = resolve(root, name) + // always delete cache first before loading config + delete require.cache[configPath] + if (await fs.pathExists(configPath)) { + debug(`loaded config at ${chalk.yellow(configPath)}`) + return require(configPath) + } } - - return userConfig + debug(`no config file found.`) + return {} } export async function resolveSiteData(