Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a main import file in ES6?

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?

like image 689
Navx Avatar asked Oct 02 '15 19:10

Navx


1 Answers

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

like image 67
JMM Avatar answered Oct 15 '22 18:10

JMM