Search code examples
javascriptecmascript-6ecmascript-5

Migration of a 'resourceManager' from ES5 to ES6


I am currently trying to migrate a project that uses a resourceManager. I tried to sketch the functionality in the picture below. It basicly made it easier to use the different services I needed. ES5 resourceManager

Now tried to migrate this to ES6 but as it is only possible to import either default or named exports. Is there a way, so I don't have to import every single function of e.g logger or atleast do that just once inside resourceManager.js and export them 'bundled' as logger? Something like this:

import {debug, error, info} as loggerFunctions from './logger.js'
export loggerFunctions as logger

So it is possible to do the following in every module using the resourceManager:

import {logger} from './resourceManager.js'
logger.debug('My debug log')
logger.error('Thats an error')
...

I really appreciate your help.


Solution

  • You can re-export all exports like this:

    export * as logger from './logger.js'
    

    MDN has a nice overview over all the valid ways to use export.