admin管理员组文章数量:1332619
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
- Related Babel Github ticket – vsync Commented May 19, 2019 at 10:34
2 Answers
Reset to default 5The 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')
本文标签: javascriptReExporting entire module in ES6BabelStack Overflow
版权声明:本文标题:javascript - Re-Exporting entire module in ES6Babel - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742267102a2443612.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论