19 lines
610 B
JavaScript
19 lines
610 B
JavaScript
// 使用 `import.meta.glob` 来同步导入所有匹配的模块
|
|
// 使用 `{ eager: true }` 选项来立即加载这些模块
|
|
const modules = import.meta.glob('./*.js', { eager: true });
|
|
|
|
const HTTP = {};
|
|
for (const path in modules) {
|
|
if (Object.hasOwnProperty.call(modules, path)) {
|
|
// 正确移除 './' 和 '.js',只保留文件名
|
|
const componentName = path.replace(/^\.\/(.*)\.\w+$/, '$1');
|
|
if (componentName !== 'index') {
|
|
// 确保我们只获取模块的默认导出
|
|
HTTP[componentName] = modules[path]?.default;
|
|
}
|
|
}
|
|
}
|
|
|
|
// 导出 HTTP 对象
|
|
export default { HTTP };
|