Re-export the entire module to ES6 / Babel

Let's say I have a module that I want to re-export:

//exportme.js export default 'EXPORTME'; export const test = () => console.log('test function'); //reexport.js export * from './exportme.js' 

When I import reexport.js, the default value from exportme.js is not available.

 //app.js import reexport from './reexport.js' console.log(reexport) //undefined 

I need to make reexport.js next to work.

 export * from './exportme.js' export default from './exportme.js' 

Is there an easier way to do this, or can it be combined into a single statement?

export default, * from './exportme.js' does not work.

I am using the latest babel with transform-export-extensions

+5
source share
2 answers

Default value from exportme.js not available

Yes, export by default is not re-exported by star export. The purpose of export * from … is to allow re-export from several modules, exporting default from several modules will only lead to collisions. Therefore, you must specify it explicitly (if you need it at all, often there is no default export along with the specified export).

Is there an easier way to do this, or can it be combined into a single statement?

No, the two lines you have are the way.

+2
source

As Bergi wrote, in one line there is no way to do this using ES 6 export. However, you can simply require the module you want to re-export and assign the result to module.exports :

 module.exports = require('./exportme.js') 
+2
source

Source: https://habr.com/ru/post/1257472/


All Articles