Created
June 29, 2019 11:13
-
-
Save negamaxi/095daa174a52f0536646a0a5434b19c2 to your computer and use it in GitHub Desktop.
Easy way to agregate eports from different files into a single object.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Assuming you have a group of modules described within individual files: | |
// - group/module1.js | |
// - group/module2.js | |
// - group/module3.js | |
// ...where each module*.js file has a corresponding named export: | |
// - group/module1.js | |
export const module1 = () => // do stuff | |
// ...and you want to aggregate them into a single object | |
// to be able to access group across the project like that: | |
import { group } from './group' | |
group.module1() | |
// To make this possible you need to reexport all the modules within a special file: | |
// - group/index.reexport.js | |
export * from './module1' | |
export * from './module2' | |
export * from './module3' | |
// ...and then aggregate all of them using index.js file and export as a single object: | |
// - group/index.js | |
import * as group from './index.reexport' | |
export { group } | |
// That's it. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment