Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow user to add Vitepress configuration to ESM packages #339

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/guide/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
25 changes: 12 additions & 13 deletions src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<UserConfig> {
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(
Expand Down