Skip to content

Commit

Permalink
feat: support function config
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Aug 13, 2021
1 parent 71b6845 commit e74c5f0
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,22 @@ export async function resolveConfig(
return config
}

export async function resolveUserConfig(root: string) {
export async function resolveUserConfig(root: string): Promise<UserConfig> {
// 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) : {}
const userConfig: UserConfig | (() => UserConfig) = hasUserConfig
? require(configPath)
: {}
if (hasUserConfig) {
debug(`loaded config at ${chalk.yellow(configPath)}`)
} else {
debug(`no config file found.`)
}

return userConfig
return typeof userConfig === 'function' ? userConfig() : userConfig
}

export async function resolveSiteData(
Expand Down

0 comments on commit e74c5f0

Please sign in to comment.