如何在ES6中创建主导入文件? [英] How do I create a main import file in ES6?
问题描述
我正在使用 ES6
语法创建一个主导入文件。我有一个组件目录,其中有一个
I am looking to create a main import file using ES6
syntax. I have a components directory with an index.js file.
如果这样做,我想要 export
导入。本质上,我想导入然后将各个组件文件导出到索引文件中,以便我可以从其他任何其他文件中解构我的导入
:
I would like to export
the imports if that makes sense. Essentially, I would like to import then export the individual component files into the index file so I can de-structure my imports
from any other files like so:
import {Comp1, Comp2} from "./components"
如何使用 ES6
语法?
推荐答案
您可以执行以下操作:
export * from "./components"
// or
export {Comp1, Comp2} from "./components"
如何引用 components / index.js
取决于您的模块加载器或您要编译的模块格式。我不知道如果您从 导出*,具有重叠命名导出的多个模块(将需要检查)会发生什么。
How exactly to reference components/index.js
depends on your module loader or the module format you're compiling to. I'm not sure what happens if you do export * from
multiple modules that have overlapping named exports (will have to check).
这篇关于如何在ES6中创建主导入文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!