javascript - Re-Exporting entire module in ES6Babel - Stack Overflow

Let's say I have a module I want to re-export:exportme.jsexport default 'EXPORTME';e

Let's say I have a module 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 from exportme.js is not available.

//app.js
import reexport from './reexport.js'

console.log(reexport) //undefined

I have to make reexport.js to be the following for it to work.

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

Is there an easier way to do this or can this be consolidated into one statement?

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

I am using latest babel with transform-export-extensions

Let's say I have a module 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 from exportme.js is not available.

//app.js
import reexport from './reexport.js'

console.log(reexport) //undefined

I have to make reexport.js to be the following for it to work.

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

Is there an easier way to do this or can this be consolidated into one statement?

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

I am using latest babel with transform-export-extensions

Share edited Oct 15, 2016 at 16:59 Michał Perłakowski 92.7k30 gold badges163 silver badges187 bronze badges asked Sep 29, 2016 at 21:01 wlingkewlingke 4,7994 gold badges37 silver badges52 bronze badges 1
  • Related Babel Github ticket – vsync Commented May 19, 2019 at 10:34
Add a ment  | 

2 Answers 2

Reset to default 5

The default from exportme.js is not available

Yes, default exports are not re-exported by star exports. The purpose of export * from … is to allow re-exports from multiple modules, exporting the default from multiple modules would only lead to collisions. You therefore have to specifiy it explicitly (if you need it at all, often there is no default export alongside named exports).

Is there an easier way to do this or can this be consolidated into one statement?

No, the two lines you have are the way to go.

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

module.exports = require('./exportme.js')

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742267103a4412006.html

相关推荐

  • javascript - Re-Exporting entire module in ES6Babel - Stack Overflow

    Let's say I have a module I want to re-export:exportme.jsexport default 'EXPORTME';e

    2天前
    50

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信