Skip to content

Instantly share code, notes, and snippets.

@negamaxi
Created June 29, 2019 11:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save negamaxi/095daa174a52f0536646a0a5434b19c2 to your computer and use it in GitHub Desktop.
Save negamaxi/095daa174a52f0536646a0a5434b19c2 to your computer and use it in GitHub Desktop.
Easy way to agregate eports from different files into a single object.
// 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