Javascript 如何在索引文件中动态导入/导出组件?

Javascript 如何在索引文件中动态导入/导出组件?,javascript,reactjs,import,frontend,export,Javascript,Reactjs,Import,Frontend,Export,如何在index.js文件中动态导入和导出文件夹中的所有模块? 我正在使用ReactJS,希望在编译应用程序时导入/导出(而不是在运行时) 以前 //index.js 从“/ComponentA”导入组件A; 从“./ComponentB”导入组件B; 从“./ComponentC”导入ComponentC; 导出{ComponentA,ComponentB,ComponentC} 之后-但不起作用 //index.js 常数fs=要求('fs'); 让组件={}; fs.readdirSyn

如何在index.js文件中动态导入和导出文件夹中的所有模块? 我正在使用ReactJS,希望在编译应用程序时导入/导出(而不是在运行时)

以前

//index.js
从“/ComponentA”导入组件A;
从“./ComponentB”导入组件B;
从“./ComponentC”导入ComponentC;
导出{ComponentA,ComponentB,ComponentC}
之后-但不起作用

//index.js
常数fs=要求('fs');
让组件={};
fs.readdirSync(uu dirname)
.filter((f)=>f!='index.js')
.forEach((文件)=>{
if(file.toLowerCase().endsWith('.js')){
filePath='./'+文件;
fileName=file.split('.')[0];
//不知道如何正确地写这部分
组件[文件名]=导入(文件路径);
}
});
导出组件;//SyntaxError:意外标记“导出”