Reputation: 111
I am using Rollup.js to put together a module from a larger number of individual JS sources. Each file contains an individual object with the exception of util.js
which, as the name suggests, contains a bunch of various helper functions and goodies = multiple exports.
I wish to export these functions with my module, but simply doing:
export * from './util';
puts all the functions directly in the main scope. I'd like to export those functions in a sub-object so instead of:
module.function1
module.function2
...
I'd get:
module.util.function1
module.util.function2
...
I know I could just import all the functions, make the object myself and then export it:
import { ... } from './util';
export const util =
{
function1 : function1,
function2 : function2,
...
};
But it feels kinda silly to write the name of each function twice on each line - is it possible to somehow automate this with Rollup.js? If so, how?
Upvotes: 2
Views: 1194
Reputation: 5415
Try to use "as" as acronym for all imports
import * as util from './util';
export {util};
Upvotes: 2