在我的 React Native 项目中,我有很多这样的代码散落在 index.js
文件中:
import Restaurant from './Restaurant';
import Store from './Store';
import Vineyard from './Vineyard';
import Wine from './Wine';
export {
Restaurant,
Store,
Vineyard,
Wine
};
写出来很重复很乏味。有没有一种方法可以自动从 index.js
重新导出当前工作目录中的所有其他文件? (注意我还在我的项目中使用了 Flow,所以任何解决方案都应该保留它可以推断的类型信息。)
谢谢。
最佳答案
export * from './Restaurant';
export * from './Store';
通过使用上述语法,您可以访问每个组件的所有导出属性并直接导出它们。
当您将所有 Action
分组到 index.js
中的每个单独的 Action
文件中并直接导出它们时,这是一种常见的模式。你可以看看 github repo
关于javascript - ES6 模块 : How to automatically re-export all types in the current directory from index. js?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50440885/