后端拆分运行时配置模块
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
import fs from 'node:fs'
|
||||
import { createRequire } from 'node:module'
|
||||
|
||||
import { isPlainObject } from './runtime-merge.js'
|
||||
|
||||
const require = createRequire(import.meta.url)
|
||||
|
||||
export function loadConfig(configPath: string): Record<string, unknown> {
|
||||
if (!fs.existsSync(configPath)) {
|
||||
return {}
|
||||
}
|
||||
|
||||
const loaded = require(configPath)
|
||||
return isPlainObject(loaded) ? loaded : {}
|
||||
}
|
||||
Reference in New Issue
Block a user