动态获取routes里面的json文件
//index.ts
const files: Record<string, any> = import.meta.glob(
'./routes/*.json',
{
eager: true
}
)
const routes = {}
for (const key in files) {
const module = files[key]
Object.assign(routes, { ...module.default })
}
例子:entity.json
最后得到
注意:如果是其他文件,如ts或js
const files: Record<string, any> = import.meta.glob(
'../router/main/**/*.{json,ts,js}',
{
eager: true
}
)
非json记得导出