diff --git a/src/node/config.ts b/src/node/config.ts index ec2ff48ab49f..4f8ebdd78cae 100644 --- a/src/node/config.ts +++ b/src/node/config.ts @@ -111,20 +111,22 @@ export async function resolveConfig( return config } -export async function resolveUserConfig(root: string) { +export async function resolveUserConfig(root: string): Promise { // 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(