简体   繁体   English

重新导出默认导出

[英]Re-export a default export

What is the best way to re-export a default export from another file? 从另一个文件重新导出默认导出的最佳方法是什么?

I'd like to do something like this: 我想做这样的事情:

export Button from './Button/Button';

Apparently this is not valid EcmaScript syntax (however it used to work in older Babel versions). 显然这不是有效的EcmaScript语法(但它曾用于较旧的Babel版本)。

As a result I want to import {Button} from 'components'; 因此,我想import {Button} from 'components';

Is there a better way, maybe a one-liner? 有没有更好的方法,也许是单线? ES6 syntax would be preffered. ES6语法将被优先考虑。

Thanks! 谢谢!

You can use the export { x as y } syntax: 您可以使用export { x as y }语法:

export { default as Button } from './Button/Button';

I'd like to do something like this: 我想做这样的事情:

export Button from './Button/Button';

There is a stage 1 proposal for this syntax: https://github.com/leebyron/ecmascript-more-export-from 这种语法有第1阶段提案: https//github.com/leebyron/ecmascript-more-export-from

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM