es6 – import all named module without alias

JavaScript solution:

import * as exports from 'foo';
Object.entries(exports).forEach(([name, exported]) => window[name] = exported);

Note: the imported wrapper object remains there.


Node.js solution:

Object.entries(require('foo')).forEach(([name, exported]) => global[name] = exported);

Leave a Comment