How do I create a main import file in ES6?

三世轮回 提交于 2020-01-02 02:11:06

问题


I am looking to create a main import file using ES6 syntax. I have a components directory with an index.js file.

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"

How do I do this with ES6 syntax?


回答1:


You can do:

export * from "./components"
// or
export {Comp1, Comp2} from "./components"

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).



来源:https://stackoverflow.com/questions/32914796/how-do-i-create-a-main-import-file-in-es6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!