Given a javascript library (let's say supportlibrary
) which has 100 named exports, I want to create my own compat-library
which exports all named exports from supportlibrary
but override a single named export with another.
For now, I can export all 99 named exports manually, but this would be a tedious job. I rather would have something like:
import {SupportComponent as ExcludedSupportComponent,...rest} from 'supportlibrary';
import SupportComponent from './MySupportComponent';
export {
...rest,
SupportComponent
}
Is something like this possible using es6 / tc39-stage-x functionality? or is this only possible with CommonJs
?
To re-export values from another file in JavaScript, make sure to export the name exports as export {myFunction, myConstant} from './another-file. js and the default export as export {default} from './another-file. js' . The values can be imported from the file that re-exported them.
ES modules are the standard for JavaScript, while CommonJS is the default in Node. js. The ES module format was created to standardize the JavaScript module system. It has become the standard format for encapsulating JavaScript code for reuse. The CommonJS module system, on the other hand, is built into Node.
Export default is used when there is only one export to be made from a particular file and when importing this one element, we don't have to worry about giving the same name to our import. This combination of export and import allows us to implement modularity.
You should be able to do
export * from 'supportlibrary';
export {default as SupportComponent} from './MySupportComponent';
to re-export all of the exports from 'supportlibrary'
, then export one additional named property that will take precedence over the export *
version.
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