In ES2015, it's possible to import an entire module as an object whose properties are the module's exports:
import * as name from 'module';
I find this to be extraordinarily useful for namespacing and use it all the time.
It's also possible to re-export other modules' exports:
export { name } from 'module'; // selectively
export * from 'other-module'; // indiscriminately
Now I'm trying to write a library with namespacing in this style. The intuitive way of collecting everything in the top-level module would be like this:
export * as name from 'module';
But that doesn't seem to work; Babel and Rollup both reject it.
I could import the module as an object, create a clone by iterating over its keys, and export that, but then it would just be a plain old dynamic object, so I would lose the great advantages Rollup provides.
So, is there really no way to do this with the declarative module syntax? It seems to me like there's no excuse for that.
export * as name from 'module';
. How would you be planning to use such an export? Importing*
always requires the namespaceas X
, so whatever name you specify in the export statement would be irrelevant anyway--right? – Inconvenientname
is the name the module object is exported with. For instance, if module "abc" containsexport * as xyz from 'xyz'
, and youimport * as abc from 'abc'
, you'll be able to access "xyz"s exports viaabc.xyz
. – Tyroexport * as Name from …
? – Forgot