Search code examples
javascriptbabeljsecmascript-6

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).

As a result I want to import {Button} from 'components';

Is there a better way, maybe a one-liner? ES6 syntax would be preferred.

Thanks!


Solution

  • You can use the export { x as y } syntax:

    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