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.
No, this was simply missed in ES6. There is a stage 1 proposal to add these, though, and rollup will consider implementing it.
Until then, you will need to use two declarations and a local binding, altough there's no need to clone the object:
import * as name from 'module';
export { name };
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With