javascript - ES6 模块 : How to automatically re-export all types in the current directory from index. js?

标签 javascript react-native ecmascript-6 flowtype commonjs

在我的 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/

相关文章:

javascript - 使用 Google-charts api 中的饼图切片将切片点击导航到不同的页面

javascript - 将我上传的图片从 1 张照片扩展到 5 张照片; map /foreach?

react-native - React Native - 如何使图像宽度 100% 和垂直顶部?

javascript - 使用导入时如何 stub ES6 node_modules?

javascript:获取函数中未破坏的参数

javascript - Node.js 中的循环多维数组

javascript - 如何在 Google Apps 脚本中使用 Dictionary javascript 类?

javascript - 隐藏/禁用 Ajax 表单的提交按钮,直到从下拉列表中进行选择

javascript - 在 JavaScript 中对 utf-8 字符串使用 encodeURI() 与 escape()

reactjs - 在 react 中带来关于过滤器的最大数据记录