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?
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With