Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any one-line analogy in ES6 for ES5 `module.exports = require('./inner.js')`?

// before
module.exports = require('./inner.js');
// nowadays
export default from './inner.js';

i'm trying to do this, but babel allow it only in es7 stage 1 as it is proposal for now. So for now, im stick to these two lines:

import sticker from './box-sticker.jsx';
export default sticker;

Can I shorter them to one?

like image 261
Vladimir Starkov Avatar asked Aug 26 '15 14:08

Vladimir Starkov


People also ask

What is the difference between import and require JS?

One of the major differences between require() and import() is that require() can be called from anywhere inside the program whereas import() cannot be called conditionally, it always runs at the beginning of the file. To use the require() statement, a module must be saved with . js extension as opposed to .

What is exports in JavaScript?

The export statement is used when creating JavaScript modules to export objects, functions, variables from the module so they can be used by other programs with the help of the import statements. There are two types of exports. One is Named Exports and other is Default Exports.


1 Answers

You should be able to do

export {default as default} from './inner.js';
// or even
export {default} from './inner.js';

with current ES6 semantics.

However I don't think there's anything wrong with using the ES next proposal, I'm pretty confident that it will make it into ES7 ES8.

like image 94
Bergi Avatar answered Oct 22 '22 12:10

Bergi