Re-export default in ES 6 modules

sanchit picture sanchit · Oct 12, 2016 · Viewed 31.6k times · Source

In ES6, is it possible to shorten the following code. I have an App.js file and an index.js.

index.js

import App from './App';

export default App;

Something like this

index.js

export default App from './App.js'

Answer

Michał Perłakowski picture Michał Perłakowski · Oct 12, 2016

If you use proposal-export-default-from Babel plugin (which is a part of stage-1 preset), you'll be able to re-export default using the following code:

export default from "./App.js"

For more information see the ECMAScript proposal.


Another way (without this plugin) is:

export { default } from "./App.js"