Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ES6, how can you export an imported module in a single line?

People also ask

Can you use module exports with import?

Modules can also contain a default export, using the default keyword. A default export will not be imported with curly brackets, but will be directly imported into a named identifier. Now the default value and named values are both available to the script.

What is module exports in es6?

The export and import are the keywords used for exporting and importing one or more members in a module. Export: You can export a variable using the export keyword in front of that variable declaration. You can also export a function and a class by doing the same.

Can you export with module exports?

Exporting values with just the exports keyword is a quick way to export values from a module. You can use this keyword at the top or bottom, and all it does is populate the module. exports object. But if you're using exports in a file, stick to using it throughout that file.


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

is the standard ES6 way, as long as you don't need Module to also be available inside the module doing the exporting.

export Module from './Module/Module';

is a proposed ESnext way to do it, but that only works if you've enabled it in Babel for now.


I don't know why but just this works for me :

components/index.js:

import Component from './Component';
import Component2 from './Component2';
import Component3 from './Component3';
import Component4 from './Component4';

export {Component, Component2, Component3, Component4};

I import the exports like this :

import {Component, Component2, Component3, Component4} from '../components';

Please note you can also re-export everything from a module:

export * from './Module/Module';

For React Native components this syntax works for me:

export {default} from 'react-native-swiper';